UVA - 10118 Free Candies
来源:互联网 发布:网络远程正规吗 编辑:程序博客网 时间:2024/05/29 07:39
题目大意:给出三个字符串,从分别从第一个字符串和第二个字符串中挑选子串a,b,用a和b组成第三个字符串,问可组成的子串有多少种。
解题思路:dp[i][j][k]表是用s1中的前i个字符和s2中的前j个字符的子串组成s3前k个字符的情况。
仿照http://www.cnblogs.com/yuzhaoxin/archive/2012/05/04/2483259.html
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int DP[45][45][45][45], A[4][45], top[4], vis[180], n;int DPS(int cur) {int &ans = DP[top[0]][top[1]][top[2]][top[3]];if (ans != -1)return ans;if (cur == 5)return 0;int maxa = 0;for (int i = 0; i < 4; i++) { if (top[i] == n)continue;int color = A[i][top[i]];top[i]++;if (vis[color]) {vis[color] = 0;maxa = max(maxa, DPS(cur-1) + 1);vis[color] = 1;}else {vis[color] = 1;maxa = max(maxa, DPS(cur+1));vis[color] = 0;}top[i]--;}return ans = maxa;}int main() {while (scanf("%d", &n), n) {for (int i = 0; i < n; i++)for (int j = 0; j < 4; j++)scanf("%d", &A[j][i]);memset(DP, -1, sizeof(DP));memset(top, 0, sizeof(top));memset(vis, 0, sizeof(vis));printf("%d\n", DPS(0));}return 0;}
0 0
- uva 10118 Free Candies
- uva 10118 - Free Candies
- UVA - 10118 Free Candies
- uva 10118 - Free Candies
- UVA 10118 - Free Candies
- UVA - 10118 Free Candies
- UVA - 10118 Free Candies
- UVa 10118 Free Candies
- uva 10118 free candies
- UVA 10118 Free Candies
- UVA 10118 Free Candies
- uva 10118 Free Candies
- UVA 10118 Free Candies
- uva 10118Free Candies
- uva 10118 Free Candies
- uva 10118 Free Candies
- Free Candies - UVa 10118 dp
- uva 10118 (Free Candies)(DP)
- Java基础(Strrng类)
- jQuery实现左移右移动画效果
- WebView 良药 android
- http和socket之长连接和短连接区别
- UVA - 753 A Plug for UNIX
- UVA - 10118 Free Candies
- 源码分析之tinyhttpd(一)
- 为什么要内存对齐 Data alignment: Straighten up and fly right
- JQuery Easy Ui dataGrid 数据表格
- 9->oracle dump日志文件和trc诊断文件
- JSP的九个内置对象
- 基于Arcgis for Js的web GIS数据在线采集简介
- UVA - 607 Scheduling Lectures
- CSDN-markdown语法之如何插入图片