UVA - 10192 - Vacation (动态规划, LCS)
来源:互联网 发布:聚游网络首页 编辑:程序博客网 时间:2024/05/22 22:47
点击打开链接
稍微修改了上面的代码提交了,LCS部分完全没错,但第一次TLE,然后修改了一下输入WA了,最后参考别人的输入才AC了。蛋疼……
题目原文:
The end of input occurs when the first sequence starts with an "#"character (without the quotes)
第一次是:scanf("%s%s", a, b) && *a!='#'第二次是:gets(a) && gets(b) && *a!='#'
第三次是:gets(a) && *a!='#'
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAX_N = 110, MAX_M = 11, INF = 0x3f3f3f3f;int N1, N2;char a[MAX_N], b[MAX_N];int d[MAX_N][MAX_N];int LCS(char a[], char b[]){memset(d, 0, sizeof(d));for(int i = 0; i < N1; i++)for(int j = 0; j < N2; j++)if(a[i] == b[j])d[i+1][j+1] = d[i][j] + 1;elsed[i+1][j+1] = max(d[i][j+1], d[i+1][j]);return d[N1][N2];}int main(){//freopen("in.txt", "r", stdin);int t = 1;while(gets(a) && *a!='#'){gets(b);N1 = strlen(a); N2 = strlen(b);printf("Case #%d: you can visit at most %d cities.\n", t++, LCS(a, b));}return 0;}
0 0
- UVA - 10192 - Vacation (动态规划, LCS)
- uva 10192 Vacation(动态规划:LCS)
- uva 10192 - Vacation(LCS)
- UVA - 10192 - Vacation (LCS)
- UVA 10192 Vacation LCS
- UVa 10192 - Vacation(LCS水题)
- UVA 10192 Vacation(dp + LCS)
- UVa 10192 Vacation (DP&LCS)
- UVA.10192 Vacation (DP LCS)
- [动态规划]UVA10192 - Vacation
- UVA - 111 History Grading (动态规划:LCS)
- UVA - 10405 Longest Common Subsequence(动态规划:LCS)
- UVA - 10066 - The Twin Towers (动态规划, LCS)
- uva 111 History Grading(动态规划:LCS)
- uva 10066 The Twin Towers(动态规划:LCS)
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
- 动态规划(二.LCS)
- uva 10192 Vacation
- 读懂常见IRP:IRP_MJ_CLEANUP\IRP_MJ_CLOSE\IRP_MJ_CREATE
- SMART原则
- 什么是以太网网桥?
- Android4.2.2 SurfaceFlinger启动流程详解(一)
- C# 和 Win32API
- UVA - 10192 - Vacation (动态规划, LCS)
- oracle修改字符集
- 习近平谈三严三实
- StringBuffer的用法
- install libncurse5-dev for menuconfig
- Can't create handler inside thread that has not called Looper.prepare()
- 行为分析数据库
- Python 数字
- 数据结构的链式存储结构