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:

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
0 0
Sample Output
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
#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;
    for (i=1;i<=n;i++)
        for (j=1;j<n;j++)
            c[i][j]= (c[i-1][j]%mod+c[i-1][j-1]%mod)%mod;
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.