Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
记忆化搜索,0ms#include <iostream> #include <stdio.h> using namespace std; long long int dp[202][202] = {0}; long long int getAns(int k, int m){ if(dp[k][m] != 0) return dp[k][m]; if(m == 0 || k == 1) return 1; long long int ans = 0; for(int s = 1; s <= m && s <= k; s++){ ans += getAns(s, m-s); } dp[k][m] = ans; return ans; } int main() { int n,k; while(1){ scanf("%d%d", &n, &k); if(n==0 && k==0) break; int m = n-k; printf("%I64d\n", getAns(k,m)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator