博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 710 E. Generate a String (dp)
阅读量:4322 次
发布时间:2019-06-06

本文共 851 字,大约阅读时间需要 2 分钟。

题目链接:

加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少。

dp[i]表示i个字符的最小代价。

当i为偶数个的时候,由+1或者*2得到。

当i为奇数个的时候,由+1或者*2-1得到。

1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include 
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 using namespace std;14 typedef __int64 LL;15 typedef pair
P;16 const int N = 1e7 + 5;17 LL dp[N];18 19 int main()20 {21 int n;22 LL x, y;23 cin >> n >> x >> y;24 dp[1] = x;25 for(int i = 2; i <= n; ++i) {26 if(i&1) {27 dp[i] = min(dp[i - 1] + x, dp[i / 2 + 1] + x + y);28 } else {29 dp[i] = min(dp[i / 2] + y, dp[i - 1] + x);30 }31 }32 cout << dp[n] << endl;33 return 0;34 }

 

转载于:https://www.cnblogs.com/Recoder/p/5837939.html

你可能感兴趣的文章
Perl按行分割文件
查看>>
根据现有表操作基于active record的model
查看>>
NotMapped属性特性
查看>>
Count and Say
查看>>
GridView数据导入Excel/Excel数据读入GridView
查看>>
566. Reshape the Matrix
查看>>
python数据结构与算法之搜索
查看>>
(最小点覆盖) poj 2226
查看>>
(树形DP) poj 3659
查看>>
获取类的属性名和值
查看>>
python对json的操作总结
查看>>
学习进度表第十一周
查看>>
js屏蔽回车键
查看>>
Memcached通用类(基于enyim.com Memcached Client)
查看>>
c#组元(Tuple)的使用
查看>>
【NO.66】转 Yahoo的军规条例
查看>>
vim基础学习之搜索功能
查看>>
session和cookie
查看>>
tftp 开发板ping不通PC机
查看>>
未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”
查看>>