codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
来源:互联网 发布:怎么域名备案 编辑:程序博客网 时间:2024/04/29 18:10
题意:
数轴上点[0, 30000]。先从 0 跳到 d, 以后每次跳的步数是 {prev-1, prev, prev+1}。跳到某个点上可以得到相应的value,求可以得到最大的value。
思路:
n, d 最大都是30000, 所以 min_step >= d-246, max_step<= d-246
所以方程 f[i, j] 当前在 i, 前一次跳的长度是 j
注意要把 [min_step, max_step] 映射到 [0, 2*246] 上面来。。
或者直接开 vector< pair<int, LL> > f[N] (pair 是 步长:目前最大value )
#include<bits/stdc++.h> using namespace std; #define SPEED_UP iostream::sync_with_stdio(false); #define FIXED_FLOAT cout.setf(ios::fixed, ios::floatfield); #define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i)) #define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i)) typedef long long LL; const int Maxn = 30000; const int D = 250; const int Maxn2 = D*2; int n, d, limi, min_step, max_step, offset; LL v[Maxn+5], f[Maxn+5][Maxn2+5]; void init() { cin >> n >> d; limi = -1; rep(i, 1, n) { int t;cin >> t;++v[t];limi = max(limi, t); } min_step = max(1, d - D); max_step = d + D; offset = min_step; } int test(int x) { int sum = 0, k = x; while (sum <= Maxn) sum += k++; max_step = k; sum = 0, k = 1; while(true) { if ((k+x)*(x-k+1)/2 < Maxn) break; ++k; } return max_step - k+1; } int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); #endif SPEED_UP init(); memset(f, -1, sizeof(f)); f[d][d-offset] = v[d]; LL ans = f[d][d-offset]; rep(i, d+1, Maxn) { if (i > limi) break; rep(j, min_step, max_step) if (i - j >= 0) { //cout << "Calc f[" << i << ", " << j << "]\n"; int t = i-j; LL _max = -1; if (f[t][j+1-offset] != -1) _max = max(_max, f[t][j+1-offset]); if (f[t][j-offset] != -1) _max = max(_max, f[t][j-offset]); if (f[t][j-1-offset] != -1) _max = max(_max, f[t][j-1-offset]); if (_max != -1) f[i][j-offset] = _max + v[i]; ans = max(ans, f[i][j-offset]); } } cout << ans << endl; return 0; }
阅读全文
0 0
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter (dp)
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
- Codeforces Round #286 C. Mr. Kitayuta, the Treasure Hunter dp
- CodeForces 505C Mr. Kitayuta, the Treasure Hunter
- CodeForces-505C Mr. Kitayuta, the Treasure Hunter
- codeforces 505C Mr. Kitayuta, the Treasure Hunter
- codeforces 505C Mr. Kitayuta, the Treasure Hunter( dp 缩减规模 )
- Codeforces 505C Mr. Kitayuta, the Treasure Hunter DP+技巧优化
- 【DP】 Codeforces Round #286 A - Mr. Kitayuta, the Treasure Hunter
- dp cf C. Mr. Kitayuta, the Treasure Hunter
- cf286C Mr. Kitayuta, the Treasure Hunter dp
- dp Codeforces505C Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter——dp
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter+dp+优化
- Codeforces Round #286 (Div. 2) C Mr. Kitayuta, the Treasure Hunter ( DP )
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter(经典的DP)
- (转载)选项卡切换
- spring4.x依赖注入方法(DI)
- 第一篇原创
- 程序员的八重境界
- SpringMvc.xml
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
- 10 扫雷游戏
- OpenCV编程->图像的平移
- python2 与 python3 不兼容问题总结【持续更新】
- 软件工程学习思考
- 素数
- 一.Node.js简介
- Jquery树插件zTree用法入门教程
- Java Class对象与反射机制