您的位置:首页 > 其它

codeforces Educational Codeforces Round 16-E(DP)

2016-08-24 17:26 477 查看
题目链接:http://codeforces.com/contest/710/problem/E

题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍),问要获得长度为n的串所需最少的时间。

思路:dp[i]表示获得长度为i的串所需要的最短时间,分i为奇数和偶数讨论。

#include<bits/stdc++.h>
using namespace std;
const int N=1e7+3;
typedef long long ll;
ll dp
;
int main()
{
int n,x,y;
scanf("%d %d %d",&n,&x,&y);
for(int i=1;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-1]+x,dp[i/2]+y);
}
printf("%I64d\n",dp
);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: