Description
【问题描述】
笨笨当了很久的道路调度员,笨笨也开始想体验生活,从生活中发现数学问题,锻炼自己思维。最近《变形金刚3》,《哈利波特7》同步放映,明显是决战雌雄,已知王府井中一共有n人买了《变形金刚3》的票,m人买了《哈利波特7》的票,并且n>=m,并且电影院中现在只有两种票,每次只有一个人买,(共有n+m次),这n+m次组成一个排列,为了保证每一个人买票时,《变形金刚3》票房都不少于《哈利波特7》,(n个买《变形金刚3》的人之间没区别,m个买《哈利波特7》的人也没区别),笨笨想着到这样的购票方案有多少种。笨笨想了好久都没想出来,所以笨笨找到了你。
【输入格式】
一行两个数n,m ( 0<=m<=n<=5000)
Input
【输入格式】
一行两个数n,m ( 0<=m<=n<=5000)
Output
【输出格式】
输出方案种数
Sample Input
1 1
Sample Output
1
Data Constraint
Hint
0<=m<=n<=5000
.
.
.
.
.
.
分析
.
.
.
.
.
.
程序:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long s,a[3001],t;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
a[3000]=1;
for (int i=n+2;i<=n+m;i++)
for (int j=3000;j>=1;j--)
{
a[j]=(long long)a[j]*i+t;
t=a[j]/100000000;
a[j]%=100000000;
}
for (int i=3000;i>=1;i--)
{
a[i]=(long long)a[i]*(n-m+1)+t;
t=a[i]/100000000;
a[i]%=100000000;
}
for (int i=1;i<=m;i++)
{
s=0;
for (int j=1;j<=3000;j++)
{
s=s*100000000+a[j];
a[j]=s/i;
s%=i;
}
}
int i=0;
while (a[i]==0) i++;
printf("%lld",a[i]);
i++;
for (;i<=3000;i++)
{
if (a[i]<10) printf("0000000"); else
if (a[i]<100) printf("000000"); else
if (a[i]<1000) printf("00000"); else
if (a[i]<10000) printf("0000"); else
if (a[i]<100000) printf("000"); else
if (a[i]<1000000) printf("00"); else
if (a[i]<10000000) printf("0");
printf("%lld",a[i]);
}
return 0;
}