| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 25331 | Accepted: 6324 |
Description
Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left:
Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?
Input
Output
Sample Input
5 4 1 1 0 0
Sample Output
126 2
Source
第一次做这个题是dp做的,学习了组合数,发现组合数更简单
无论怎么走肯定要走n+m这么长的路,在这么长的路里选n个向下走的
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
ll myc(ll n,ll r)
{
ll sum=1;
for(int i=1;i<=r;i++)
{
sum=sum*(n-i+1)/i;
}
return sum;
}
int main()
{
ll a,b;
while(~scanf("%lld %lld",&a,&b),a+b)
{
if(a==0||b==0)
printf("1\n");
else
printf("%lld\n",myc(a+b,a));
}
return 0;
}
2万+



被折叠的 条评论
为什么被折叠?



