传送门:http://codeforces.com/problemset/problem/710/E

分析: 让你写一个全由"a"组成的长为n的串,告诉你两种操作,第一种:插入一个字母或者删除一个字母需要花费x秒,

第二种:复制现有的串,并加入到原来的穿上,花费y秒,问你最少花费多少时间? 用dp[i]表示需要花费的最少时间,‘

然后对i为偶数的情况取min(dp[i-1] +x,dp[i/2]+y),当i为奇数时min(dp[i-1] + x, min(dp[i/2+1] + y + x,dp[i/2] + y + x))。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7+;
ll dp[maxn]; int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,x,y;
cin >> n >> x >> y;
memset(dp,,sizeof(dp));
for(int i = ; i<= n; i++)
{
if(i&)
dp[i] = min(dp[i-] + x, min(dp[i/+] + y + x,dp[i/] + y + x));
else
dp[i] = min(dp[i/] +y, dp[i-] +x);
}
cout << dp[n] << endl;
return ;
}

最新文章

  1. 使用MyEclipse中servlet对SQL Server 2008的CRUD
  2. vi编辑器 使用 命令
  3. 一行代码如何控制ipunt框里面值的长度
  4. scrollHeight,scrollLeft,offsetHeight,offsetLeft
  5. jsp页面的forEach和判断
  6. Redis-cluster集群【第二篇】:redis持久化
  7. c++流的读写
  8. ID3
  9. VS2008注册码
  10. kaggle之数字序列预测
  11. DB Query Analyzer 5.04 is released, 63 articles concerned have been published
  12. java多线程(同步和死锁,生产者和消费者问题)
  13. [CVPR2017] Visual Translation Embedding Network for Visual Relation Detection 论文笔记
  14. Mybatis Generator 生成的mapper只有insert方法
  15. java笔试总结
  16. 配置apache使用https访问
  17. HDUOJ-----2824The Euler function
  18. appium格式化循环点击
  19. oracle OEM安装(一)
  20. CSS基础(续)

热门文章

  1. 一张图说docker
  2. Vue2.0父子组件间事件派发机制
  3. [HAOI2009]毛毛虫(树形dp)
  4. 高并发web系统设计
  5. LaTeX 设置字体颜色
  6. [MST] Create Dynamic Types and use Type Composition to Extract Common Functionality
  7. hadoop学习;datajoin;chain签名;combine()
  8. java 基本类型、包装类、字符串之间的转换
  9. CF 558D(Guess Your Way Out! II-set解决区间问题)
  10. Logical Operators (Transact-SQL)