UVA 10192 - Vacation
2014-10-21 22:44
274 查看
还是dp最长公共子序列。
#include <iostream> #include <limits> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; const int size = 100 + 10; char a[size] , b[size]; int d[size][size]; int dp(int x , int y) { if(d[x][y] >=0) return d[x][y]; if(!x || !y) return d[x][y] = 0; if(a[x-1] == b[y-1]) return d[x][y] = dp(x-1 , y-1) + 1; else return d[x][y] = max(dp(x-1 , y) , dp(x , y-1)); } int main() { int cnt = 0; while(fgets(a , size , stdin) && a[0] != '#' && fgets(b , size , stdin)) { int a_len = strlen(a); int b_len = strlen(b); memset(d , -1 , sizeof(d)); printf("Case #%d: you can visit at most %d cities.\n" , ++cnt , dp(a_len-1 , b_len-1)); } return 0; }
相关文章推荐
- UVa 10192 - Vacation
- UVa 10192 - Vacation
- UVa 10192 - Vacation
- uva 10192 - Vacation(简单的最长公共子序列)
- UVA 10192 Vacation
- UVA 10192 Vacation
- UVA 10192 Vacation
- uva 10192 Vacation(动态规划:LCS)
- UVa 10192: Vacation
- uva10192-Vacation
- UVA - 10192 - Vacation (LCS)
- UVA10192- Vacation
- uva 10192 - Vacation(LCS)
- uva 10192 - Vacation
- uva 10192 Vacation
- UVa 10192 - Vacation
- UVA - 10192 Vacation
- UVa 10192 Vacation
- uva10192 - Vacation(dp,lcs)
- uva 10192 Vacation