codeforces 710E Generate a String(简单dp)
2024-08-31 14:13:31
传送门: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 ;
}
最新文章
- 使用MyEclipse中servlet对SQL Server 2008的CRUD
- vi编辑器 使用 命令
- 一行代码如何控制ipunt框里面值的长度
- scrollHeight,scrollLeft,offsetHeight,offsetLeft
- jsp页面的forEach和判断
- Redis-cluster集群【第二篇】:redis持久化
- c++流的读写
- ID3
- VS2008注册码
- kaggle之数字序列预测
- DB Query Analyzer 5.04 is released, 63 articles concerned have been published
- java多线程(同步和死锁,生产者和消费者问题)
- [CVPR2017] Visual Translation Embedding Network for Visual Relation Detection 论文笔记
- Mybatis Generator 生成的mapper只有insert方法
- java笔试总结
- 配置apache使用https访问
- HDUOJ-----2824The Euler function
- appium格式化循环点击
- oracle OEM安装(一)
- CSS基础(续)
热门文章
- 一张图说docker
- Vue2.0父子组件间事件派发机制
- [HAOI2009]毛毛虫(树形dp)
- 高并发web系统设计
- LaTeX 设置字体颜色
- [MST] Create Dynamic Types and use Type Composition to Extract Common Functionality
- hadoop学习;datajoin;chain签名;combine()
- java 基本类型、包装类、字符串之间的转换
- CF 558D(Guess Your Way Out! II-set解决区间问题)
- Logical Operators (Transact-SQL)