bjfu1332 简单动规
2015-06-05 21:47
288 查看
挺简单的动态规划题。我用记忆化搜索打的。直接上代码:
/* * 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] > -1) { return ans[m] ; } if (card[m] > n) { ans[m] = dfs(m - 1, n); } else { ans[m] = dfs(m - 1, n - card[m]) + dfs(m - 1, n); } return ans[m] ; } 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; }
相关文章推荐
- 去除开机自动弹出的“Enter password to unlock your login keyring”对话框
- Linux终端下的命令
- 随笔7
- Git远程操作详解
- Maximal Square || LeetCode
- 海量数据处理技术(1): 散列技术
- 单元测试解决HttpContext的问题
- quick接入SDK
- icpc2015 D Cutting Cheese(二分+球缺体积)
- IDF实验室-特殊的日子
- QQ通信原理及QQ是怎么穿透内网进行通信的?
- [GUI] QT事件与X11的关系
- String to Integer (atoi)
- 单元测试解决HttpContext的问题
- 面试题22 栈的压入、弹出序列
- Activity dispatchTouchEvent事件分发--测试(一)
- [hdu4495]二分,字符串hash,DP
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- An Adaptive Communication Architecture for Wireless Sensor Networks
- 归一化