Codeforces 710 E. Generate a String (dp)
2016-09-03 20:45
447 查看
题目链接:http://codeforces.com/problemset/problem/710/E
加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少。
dp[i]表示i个字符的最小代价。
当i为偶数个的时候,由+1或者*2得到。
当i为奇数个的时候,由+1或者*2-1得到。
加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少。
dp[i]表示i个字符的最小代价。
当i为偶数个的时候,由+1或者*2得到。
当i为奇数个的时候,由+1或者*2-1得到。
//#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; typedef __int64 LL; typedef pair <int, int> P; const int N = 1e7 + 5; LL dp ; int main() { int n; LL x, y; cin >> n >> x >> y; dp[1] = x; for(int i = 2; i <= n; ++i) { if(i&1) { dp[i] = min(dp[i - 1] + x, dp[i / 2 + 1] + x + y); } else { dp[i] = min(dp[i / 2] + y, dp[i - 1] + x); } } cout << dp << endl; return 0; }
相关文章推荐
- Atlantis(离散化)
- C++ 对象的内存布局(上)
- 从决策树学习谈到贝叶斯分类算法、EM、HMM
- IntentService的源码分析
- 哈理工OJ 1681“回文串”
- Linux 下编译C语言
- 错误“AxImp.exe”已退出,代码为 -1163019603【转载及个人看法】
- BGRABitmap图像操作6:前面的长方形改成既有圆角又有尖角
- IP问题(1)
- Caffe学习笔记(六)—— Windows下训练自己的数据
- UVa1583 - Digit Generator 生成元 (java版本)
- [leetcode] Maximum Subarray
- 关于javaEE的web项目——WEB-INF
- ios属性和实例变量
- 堆和栈的区别
- CVTE面试总结
- BroadCast Receiver的使用
- 魔都一月记
- 完美世界运营培训生内推笔试题
- hiho1362 修补木桶