码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 10943 How do you add?

时间:2015-07-27 10:49:09      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

          How do you add?

Larry is very bad at math — he usually uses a calculator, which
worked well throughout college. Unforunately, he is now struck in
a deserted island with his good buddy Ryan after a snowboarding
accident.
They’re now trying to spend some time figuring out some good
problems, and Ryan will eat Larry if he cannot answer, so his fate
is up to you!
It’s a very simple problem — given a number N, how many ways
can K numbers less than N add up to N?
For example, for N = 20 and K = 2, there are 21 ways:
0+20
1+19
2+18
3+17
4+16
5+15
...
18+2
19+1
20+0

Input
Each line will contain a pair of numbers N and K. N and K will both be an integer from 1 to 100,
inclusive. The input will terminate on 2 0’s.


Output
Since Larry is only interested in the last few digits of the answer, for each pair of numbers N and K,
print a single number mod 1,000,000 on a single line.


Sample Input
20 2
20 2
0 0


Sample Output
21
21

 

 

 

 

map[i][j]=map[i-1][j]+map[i][j-1];

 

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 int main()
 7 {
 8     int map[105][105];
 9     int k;
10     memset(map,0,sizeof(map));
11     for(int i=1;i<101;i++)
12     {
13         map[i][1]=1;
14         map[1][i]=i;
15     }
16     for(int i=2;i<101;i++)
17     {
18         for(int j=2;j<101;j++)
19         {
20             map[i][j]=map[i-1][j]+map[i][j-1];
21             if(map[i][j]>1000000)
22                 map[i][j]%=1000000;
23         }
24     }
25     int a,b;
26     while(cin>>a>>b)
27     {
28         if(a==0&&b==0)
29             break;
30         cout<<map[a][b]<<endl;
31     }
32     return 0;
33 }

 

UVA 10943 How do you add?

标签:

原文地址:http://www.cnblogs.com/moqitianliang/p/4679235.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!