首页 > 代码库 > UVA 10943 How do you add?

UVA 10943 How do you add?

设函数 f(k)(n);

则:

  f(1)(n)=1;

  f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n);

  f(3)(n)=f(2)(0)+f(2)(1)+f(2)(2)+...+f(2)(n);

        . 

        .

        .

  f(k)(n)=f(k-1)(0)+f(k-1)(1)+...+f(k-1)(n);

 

可预处理。

 

附代码:

#include <iostream>
#include <cstring>
using namespace std;

int main (){
int n,k;
int f[110][110];
memset (f,0,sizeof f);
for (int i=0;i<=100;i++)
f[1][i]=1;
for (int i=2;i<=100;i++){
for (int j=0;j<=100;j++){
for (int o=0;o<=j;o++)
f[i][j]=(f[i][j]+f[i-1][o])%1000000;
}
}
while (cin>>n>>k&&(n+k)){
cout<<f[k][n]<<endl;
}
return 0;
}