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;
}
题意:开始文本为空,可以选择话费时间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;
}
相关文章推荐
- Educational Codeforces Round 16 E. Generate a String-DP
- Educational Codeforces Round 16 E. Generate a String dp
- Educational Codeforces Round 16 E. Generate a String (DP)
- DP方程——Generate a String ( Educational Codeforces Round 16 E)
- Educational Codeforces Round 16 E. Generate a String (dp)
- Educational Codeforces Round 16 -- E. Generate a String (DP)
- Educational Codeforces Round 16 B
- codeforces Educational Codeforces Round 16-C
- Educational Codeforces Round 1 E.Chocolate Bar(DP)
- Educational Codeforces Round 16-C. Magic Odd Square
- Codeforces Educational Codeforces Round 16 部分题解
- Educational Codeforces Round 16 C
- Educational Codeforces Round 16 C. Magic Odd Square
- Educational Codeforces Round 39 (Rated for Div. 2)D. Timetable(dp)
- Educational Codeforces Round 16 -- C - Magic Odd Square (找规律)
- 【解题报告】Educational Codeforces Round 16
- Educational Codeforces Round 16 E 题 Generate a String
- codeforces Educational Round 16 E. Generate a String
- Educational Codeforces Round 26 D. Round Subset(dp)
- Educational Codeforces Round 40 (Rated for Div. 2) F. Runner's Problem 前缀和求区间覆盖 矩阵快速幂优化DP 离散化