codeforces 710E Generate a String(简单dp)
传送门: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 ;
}
codeforces 710E Generate a String(简单dp)的更多相关文章
- CodeForces - 710E Generate a String (dp)
题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...
- CodeForces 710E Generate a String (DP)
题意:给定 n,x,y,表示你要建立一个长度为 n的字符串,如果你加一个字符要花费 x时间,如果你复制前面的字符要花费y时间,问你最小时间. 析:这个题,很明显的DP,dp[i]表示长度为 i 的字符 ...
- 【动态规划】【最短路】Codeforces 710E Generate a String
题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...
- CodeForces 710E Generate a String
$SPFA$,优化,$dp$. 写了一个裸的$SPFA$,然后加了一点优化就过了,不过要$300$多$ms$. $dp$的话跑的就比较快了. $dp[i]$表示输入$i$个字符的最小花费. 首先$dp ...
- Educational Codeforces Round 16 E. Generate a String (DP)
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...
- Codeforces - 706B - Interesting drink - 二分 - 简单dp
https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $ ...
- Codeforces - 9D - How many trees? - 简单dp - 组合数学
https://codeforces.com/problemset/problem/9/D 一开始居然还想直接找公式的,想了想还是放弃了.原来这种结构是要动态规划. 状态是知道怎么设了,$t_{nh} ...
- codeforces 710E E. Generate a String(dp)
题目链接: E. Generate a String time limit per test 2 seconds memory limit per test 512 megabytes input s ...
- Educational Codeforces Round 16 E. Generate a String dp
题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...
随机推荐
- 紫书 习题 8-23 UVa 1623 (set妙用 + 贪心)
这道题我是从样例中看出思路了 2 4 0 0 1 1 看这组数据, 输出的是No, 为什么呢?因为两个1之间没有神龙喝水, 所以一定会有水灾. 然后就启发了我,两次同一个湖的降水之间必须至少有一次神龙 ...
- Camera Calibration 相机标定:原理简介(一)
1 相机标定常见方法 广义来说,相机标定不单包括成像过程的几何关系标定,还包括辐射关系的标定,本文只探讨几何关系.相机标定是3D计算机视觉(Computer Vision)里从2D图像中提取量测信息的 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- linux 流量统计小程序
源代码例如以下: //2015/7/2 10:30:35 //gino #include <stdio.h> #include <sys/stat.h> #include &l ...
- bzoj1193: [HNOI2006]马步距离(贪心+bfs)
1193: [HNOI2006]马步距离 题目:传送门 题解: 毒瘤题... 模拟赛时的一道题,刚开始以为是一道大难题...一直在拼命找规律 结果.... 还是说正解吧: 暴力的解法肯定是直接bfs, ...
- visual studio code(vscode)的使用(快捷键)
Visual Studio Code初探 vscode 是一种可运行于 OS X,Windows 和 Linux 之上的免费跨平台编辑器: 1. 快捷键 ctrl + `:调出(对于 windows ...
- Frame Stacking ZOJ 1083,poj 1128
Frame Stacking Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4034 Accepted: 1352 De ...
- 10.bitset
#include <iostream> //位运算,处理二进制非常方便,线性存储 #include <bitset> #include <string> using ...
- 虚拟主机TOMCAT配置
在tomcat中添加虚拟主机: 编辑"tomcat\conf\server.xml",在"<Engine></Engine>"元素中新加 ...
- CF 986C AND Graph(建模+DFS)
#include<stdio.h> ],v[]; ],n,al; void dfs(int x){ if(v[x])return; v[x]=; if(ex[x])dfs(al^x); ; ...