... HAVE U TRIED .... AT LEAST 3 TIMES ... OK U CAN SEE THIS ...

Saturday, January 4, 2014

UVA-10943 :: How do you add?

//Problem link>>http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1884

#include <bits/stdc++.h>
#define mod 1000000
using namespace std ;

int dp[106][106] ;

int call (int n, int k)
{
    if (n<0 || k<0) return 0 ;
    int rez=0 ,i ;

    int  &dos=dp[n][k] ;
    if (dos != -1) return dos ;

    for (i=0 ; i<=n ; i++)
    {
        rez= (rez + call(n-i , k-1) )% mod ;
    }
    dos = rez ;
    return dos ;
}

int main ()
{
    int n , k  ;
    while (cin>>n>>k && n || k )
    {
        memset(dp,-1,sizeof (dp)) ;
        dp[0][0]=1 ;
        cout<<call(n,k) <<endl ;
    }

    return 0 ;
}

No comments:

Post a Comment