热门搜索: 个人免签支付 素材网站源码 图片素材站源码 游戏源码 js广告 jquery选项卡 jQuery导航
2020-12-13 15:57
标签:lcs dp 动态规划 DP,题目很长,题意就是求LCS。 #include #include #include #include #include #include #include #include #include #include #include #include #define INF 0x7fffffff #define eps 1e-8 #define LL long long #define PI 3.141592654 #define CLR(a,b) memset(a,b,sizeof(a)) #define FOR(i,a,n) for(int i= a;i=b;i--) #define pb push_back #define mp make_pair #define ft first #define sd second #define sf scanf #define pf printf #define acfun std::ios::sync_with_stdio(false) #define SIZE 100+1 using namespace std; int a[SIZE],b[SIZE],dp[SIZE][SIZE]; int main() { int la,lb; int ca=1; while(~sf("%d%d",&la,&lb),la||lb) { FOR(i,0,la) sf("%d",&a[i]); FOR(i,0,lb) sf("%d",&b[i]); CLR(dp,0); FOR(i,0,la) FOR(j,0,lb) { if(a[i]==b[j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]); } pf("Twin Towers #%d\n",ca++); pf("Number of Tiles : %d\n\n",dp[la][lb]); } } UVA 10066 The Twin Towers 标签:lcs dp 动态规划 原文地址:http://blog.csdn.net/dongshimou/article/details/40855427
标签:lcs dp 动态规划
DP,题目很长,题意就是求LCS。
#include #include #include #include #include #include #include #include #include #include #include #include #define INF 0x7fffffff #define eps 1e-8 #define LL long long #define PI 3.141592654 #define CLR(a,b) memset(a,b,sizeof(a)) #define FOR(i,a,n) for(int i= a;i=b;i--) #define pb push_back #define mp make_pair #define ft first #define sd second #define sf scanf #define pf printf #define acfun std::ios::sync_with_stdio(false) #define SIZE 100+1 using namespace std; int a[SIZE],b[SIZE],dp[SIZE][SIZE]; int main() { int la,lb; int ca=1; while(~sf("%d%d",&la,&lb),la||lb) { FOR(i,0,la) sf("%d",&a[i]); FOR(i,0,lb) sf("%d",&b[i]); CLR(dp,0); FOR(i,0,la) FOR(j,0,lb) { if(a[i]==b[j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]); } pf("Twin Towers #%d\n",ca++); pf("Number of Tiles : %d\n\n",dp[la][lb]); } }
UVA 10066 The Twin Towers
原文地址:http://blog.csdn.net/dongshimou/article/details/40855427
上一篇:敌兵布阵 (树状数组+前缀和)
下一篇:python os 模块