codeforces Educational Codeforces Round 16-E(DP)

题目链接: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[N];
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[n]);
return 0;
}
上一篇:Understanding about numerical stability, convergence and consistency


下一篇:关系网络数据可视化:1. 关系网络图&Gephi