题目来源:http://codeforces.com/problemset/problem/1207/C
对DP(记忆化搜索)还是不是太有感觉,赛中遇到的都是想着贪心,遇到0-1或者1-0的间隔点对前一个区间进行贪心就好了,赛中贪的不行,应跳出思维,直接对每一段进行dp即可,递增最优解。(题目中读题要仔细,第一个和最后一个都是0)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll dp[200100][2];
char s[200100];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,a,b;
scanf("%d%d%d", &n, &a, &b);
scanf("%s", s);
dp[0][0]=b,dp[0][1]=1e18;
for(int i=0;i<n;i++)
{
if(s[i]=='0')
{
dp[i+1][1]=min(dp[i][0]+a*2+2*b,dp[i][1]+a+b*2);
dp[i+1][0]=min(dp[i][0]+a+b,dp[i][1]+a*2+b);
}
else
{
dp[i+1][1]=dp[i][1]+a+2*b,dp[i+1][0]=1e18;
}
}
printf("%I64d\n",dp[n][0]);
}
return 0;
}