UVa 10192 Vacation:DP&LCS

10192 - Vacation

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1133

水。

完整代码:

/*0.019s*/

#include<bits/stdc++.h>
using namespace std;  

char a[105], b[105];
int dp[105][105];  

int main()
{
    int lena, lenb, i, j, cas = 0;
    while (gets(a), a[0] != '#')
    {
        gets(b);
        lena = strlen(a), lenb = strlen(b);
        memset(dp, 0, sizeof(dp));
        for (i = 0; i < lena; ++i)
            for (j = 0; j < lenb; ++j)
            {
                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]);
            }
        printf("Case #%d: you can visit at most %d cities.\n", ++cas, dp[lena][lenb]);
    }
    return 0;
}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索dp
, int
, http
strlen
,以便于您获取更多的相关知识。

时间: 2024-10-26 21:45:21

UVa 10192 Vacation:DP&amp;LCS的相关文章

UVa 531 Compromise:DP&amp;amp;LCS

531 - Compromise Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=472 注意用一个全局变量flag来确定是否输出空格. 完整代码: /*0.029s*/ #include<bits/stdc++.h> using namespac

UVa 10066 The Twin Towers:DP&amp;amp;LCS

10066 - The Twin Towers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1007 水. 完整代码: /*0.012s*/ #include<bits/stdc++.h> using namespace std; int a

UVa 11137 Ingenuous Cubrency (DP)

11137 - Ingenuous Cubrency Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2078 People in Cubeland use cubic coins. Not only the unit of currency is called acube but also

UVa 674 Coin Change (DP)

674 - Coin Change Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=615 Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent.

UVa 10003 Cutting Sticks (DP)

10003 - Cutting Sticks Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=944 You have to cut a wood stick into pieces. The most affordable company, The Ana

UVa 147 Dollars:经典DP&amp;amp;硬币组合数&amp;amp;整数拆分

147 - Dollars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 和UVa 357一样. 注意所有数除以5再算. 完整代码: /*0.019s*/ #include<cstdio> #include<cstring> const int coin[11

UVa 10313 Pay the Price:DP&amp;amp;整数拆分

10313 - Pay the Price Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1254 In ancient days there was a country whose people had very interesting habits.

UVa 437 The Tower of Babylon:DP&amp;amp;DAG

437 - The Tower of Babylon Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=378 思路: 对于一个(x,y,z)砖头,它可以有3中姿势放置: (前两个为地面,后一个为高) x, y, z x, z, y y, z, x 把每种姿势

UVa 10651 Pebble Solitaire:DP&amp;amp;bitset

10651 - Pebble Solitaire Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1592 化为二进制进行状态转移,详见代码. 完整代码: /*0.016s*/ #include<bits/stdc++.h> using names