UVA 10943How Do you add? (Simple combination)

Source: Internet
Author: User
problem a: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 and his good buddy Ryan after a snowboarding accident. They ' re now trying to spend some time figuring out some good problems, and Ryan would eat Larry if he cannot answer, so he Fate is up to you!

It's a very simple problem-given a number N, what many ways can K numbers less than n add up to n?

For example, for N = 2 and K = +, there is ways:
0+20
1+19
2+18
3+17
4+16
5+15
...
18+2
19+1
20+0


InputEach line would contain a pair of numbers N and K. N and K would both be a integer from 1 to inclusive. The input would terminate on 2 0 ' s. OutputSince 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.

Sample Input
2
2
0 0
Sample Output
21
Test instructions: give you n and K, so that you can find the number of K and N of the species (0); Obviously the plate method, the n is considered as N 1, because it can be 0, so also add K 0, that is 1 1 1 1 ... 0 0 0 0, then a total of n+k-1 empty, insert K-1 board, so the final result
Code:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <stdlib.h>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <set>
# Define INF 0x3f3f3f3f
#define EPS 1e-5
#define MAX (a) > (b)? ( A):(B)
#define MIN (a) (a) < (b)? ( A):(B)
#define N
#define MOD 1000000
using namespace std;
int c[n+1][n+1];
void init ()
{
    int i,j;
    C[0][0]=1;
    for (i=1;i<=n;i++)
    {
        c[i][0]=1;
        for (j=1;j<n;j++)
        {
            c[i][j]= (c[i-1][j]%mod+c[i-1][j-1]%mod)%mod;
        }
        c[i][n]=1;
    }
}
int main ()
{
    int n,k,ans,i;
    Init ();
    while (~SCANF ("%d%d", &n,&k) && (n| | k)
    {
        printf ("%d\n", C[n+k-1][k-1]);
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.