专题三acm1002

来源:互联网 发布:淘宝商家客服服务电话 编辑:程序博客网 时间:2024/06/06 06:55

Problem Description
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = &lt;x1, x2, ..., xm&gt; another sequence Z = &lt;z1, z2, ..., zk&gt; is a subsequence of X if there exists a strictly increasing sequence &lt;i1, i2, ..., ik&gt; of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = &lt;a, b, f, c&gt; is a subsequence of X = &lt;a, b, c, f, b, c&gt; with index sequence &lt;1, 2, 4, 6&gt;. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y. <br>The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line. <br>
 

Sample Input
abcfbc abfcabprogramming contest abcd mnp
 

Sample Output
420
(1)大意:
给出两个序列X、Y,让我们编写一个程序,求出这两个序列最长的公共上升子序列。
(2)思路:
与课上讲的例题,十分相似,所以不再多说,用动态规划的思想,排除重复计算,得到最后的结果。
(3)感想:
消化课上讲的,就很好,这些问题就能很好的解决。
(4)
#include <iostream>#include <cstdio>using namespace std;int main(){    int i,ca=1,t,s,e,n,x,now,before,max;    scanf("%d",&t);    while(t--)    {       scanf("%d",&n);       for(i=1;i<=n;i++)       {         scanf("%d",&now);         if(i==1)         {            max=before=now;            x=s=e=1;         }         else {             if(now>now+before)             {                before=now;                x=i;             }             else before+=now;              }         if(before>max)           {max=before,s=x,e=i;}       }       printf("Case %d:\n%d %d %d\n",ca++,max,s,e);       if(t)    {     printf("\n");    }    }    return 0;}
0 0