您的位置:首页 > 其它

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得到。

//#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: