Ural1079-Maximum
2016-11-15 15:22
253 查看
递归预处理
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 100000 + 5; int a[maxn]; int f(int x) { if (x == 0 || (x != 0 && a[x])) { return a[x]; } if (x % 2 == 0) { return f(x/2); } else { return f((x-1)/2) + f((x-1)/2+1); } } int main(int argc, char const *argv[]) { a[0] = 0; a[1] = 1; for (int i = 2; i < 100000; i++) { a[i] = f(i); } int n; while (scanf("%d", &n) == 1 && n) { printf("%d\n", *max_element(a, a + n + 1)); } return 0; }
相关文章推荐
- URAL 1079 Maximum 递推
- Ural 1079 - Maximum
- URAL1079:Maximum
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
- ural 1146. Maximum Sum dp
- URAL1079
- 51nod 1062 && URAL 1079 Maximum RMQ
- Leetcode: Maximum Depth of Binary Tree
- Ural 1114(49/600)
- URAL 2017 Best of a bad lot 二分图染色 使x集点数最少
- 【Leetcode】【python】Maximum Depth of Binary Tree
- [LeetCode] Maximum Product Subarray
- LeetCode - 628 - Maximum Product of Three Numbers
- LeetCode:Maximum Subarray
- 2017多校联合第二场 1003题 hdu 6047 Maximum Sequence O(n) (有理有据地)贪心
- POJ 3693 Maximum repetition substring(后缀数组)
- Lintcode97 Maximum Depth Of BinaryTree solution 题解
- [leetcode]Maximum Product Subarray
- PLSQL result set exceeds the maximum size(100M)if necessary,you can explicitly confinue this query
- [leetcode]Maximum Product Subarray