A Wonderful Concert | ||||||
| ||||||
Description | ||||||
Recently ,a famous singer will come to our school ,and he is going to host a concert in the assembly hall .Because of the high popularity of this singer ,many student have great willing to come to this concert. As you know , this concert’s ticket price is 50 yuan .Some day ,there are m students who only have 50 yuan and n students who only have 100 yuan coming to buy ticket . But a horrible thing happened ,the ticket seller don’t have any change . Now , this is your show time .Please tell the ticket seller the kind of queuing ways that all people can buy ticket without problem .Obviously ,everyone can only buy one ticket . | ||||||
Input | ||||||
The input file contains multiple test cases. For each test case: it contains two integer m and n . You should proceed to the end of file. Hint: 1 <= n <= m <= 1000 | ||||||
Output | ||||||
For each test case, output the total ways.Because this number may be too large ,you just output the values mod 1000000007. | ||||||
Sample Input | ||||||
1 1
2 1
2 2
| ||||||
Sample Output | ||||||
1
2
2
| ||||||
Source | ||||||
CPC23 2014-6 | ||||||
Author | ||||||
Zhou Ben |
题目大意:
一个商店一开始没有零钱,一张票50块钱,我们有n个人有50块钱,m个人有100块钱,问我们可以有多少种分配方案,使得所有100块钱的同学买票的同时会被找零。
思路:
设定Dp【i】【j】表示现在有i个50块钱j个100块钱的顾客的排列方案。
那么有:Dp【i】【j】=Dp【i-1】【j】+Dp【i】【j-1】;
Ac代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int dp[1005][1005];
void init()
{
dp[0][0]=1;
for(int i=0;i<=1000;i++)
{
for(int j=0;j<=i;j++)
{
if(i==0&&j==0)continue;
dp[i][j]=dp[i-1][j]+dp[i][j-1];
dp[i][j]%=1000000007;
}
}
}
int main()
{
init();
int n,m;
while(~scanf("%d%d",&n,&m))
{
printf("%d\n",dp[n][m]%1000000007);
}
}