规律题
k 1 2 3 4 5 6 7 8....
1 1 2 3 4 5 6 7 8....
2 1 3 6 10 15 20...
3 1 4 10 20 35 55...
就是dp[i][j]=dp[i-1][j]+dp[i-1][j]
#include <cstring> #include <cstdio> #define N 110 #define mod 1000000 int dp[N][N]; void solve() { memset(dp, 0, sizeof(dp)); for(int i=1; i<N; ++i) dp[i][1]=dp[0][i]=1; for(int i=1; i<N; ++i) { for(int j=2; j<N; ++j) { dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod; } } } int main() { int n,k; solve(); while(scanf("%d %d",&n,&k)==2) { if(!n && !k) return 0; printf("%d\n",dp[n][k]); } return 0; }