标签:style blog io ar for on 2014 log ad
思路和1080一样
题目有几个坑:
范围要开到2010,题目没有给
子弹数量和恐怖分子出现的字符串长度不一定相等
用memset会超时
#include "stdio.h" #include "string.h" int dp[2010][2010],a[2010]; int Max(int a,int b,int c) { int x; x=a; if (b>x) x=b; if (c>x) x=c; return x; } int main() { int n,i,j,x,y,z,len_a,len_b; char key[2010],str_a[2010],str_b[2010]; while (scanf("%d",&n)!=EOF) { scanf("%s",key); for (i=0;i<n;i++) scanf("%d",&a[key[i]]); scanf("%s %s",str_a,str_b); len_a=strlen(str_a); len_b=strlen(str_b); for (i=1;i<=n;i++) dp[0][i]=dp[i][0]=0; dp[0][0]=0; for (i=1;i<=len_a;i++) for (j=1;j<=len_b;j++) { x=dp[i-1][j]; y=dp[i][j-1]; z=dp[i-1][j-1]; if (str_a[i-1]==str_b[j-1]) z+=a[str_a[i-1]]; dp[i][j]=Max(x,y,z); } printf("%d\n",dp[len_a][len_b]); } return 0; }
标签:style blog io ar for on 2014 log ad
原文地址:http://blog.csdn.net/u011932355/article/details/40780489