bjfu1332 简单动规
挺简单的动态规划题。我用记忆化搜索打的。直接上代码:
/* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; typedef long long LL; const int card[53] = {0, 1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13}; int ans[53][60]; int dfs(int m, int n) { if (n == 0) { return 1; } if (m == 0) { return 0; } if (ans[m][n] > -1) { return ans[m][n]; } if (card[m] > n) { ans[m][n] = dfs(m - 1, n); } else { ans[m][n] = dfs(m - 1, n - card[m]) + dfs(m - 1, n); } return ans[m][n]; } int main() { int T, n; scanf("%d", &T); memset(ans, -1, sizeof(ans)); while (T--) { scanf("%d", &n); printf("%d\n", dfs(52, n)); } return 0; }