标题:为什么一直是Wrong Answer?哪里的代码有问题?
只看楼主
glglzb
Rank: 2
等 级:论坛游民
帖 子:47
专家分:22
注 册:2011-10-12
结帖率:93.33%
已结贴  问题点数:20 回复次数:2 
为什么一直是Wrong Answer?哪里的代码有问题?
1007. Common Subsequence
总提交数量:    522    通过数量:    90
           
时间限制:1秒    内存限制:256兆
题目描述
 A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm>, another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence(严格递增) <i1, i2, ..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.

输入格式
 The first line is a positive integer N (1 <= N <= 10000), giving the number of the test cases.
Each test case contains two strings representing the given sequences. The sequences are separated by any number of white spaces. Both the length of the sequences are less than 15.

输出格式
 For each test case, the program prints the length of the maximum-length common subsequence from the beginning of a separate line.

样例输入
 将样例输入复制到剪贴板
3
abcfbc  abfcab
programming  come
abcd  mnp
样例输出
4
2
0
我的做法是:
#include <string.h>
int main()
{
    int n,i,j,k,counter;
    char b[15], a[15];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        k=0;
        counter = 0;
        scanf("%s",b);
        scanf("%s",a);
        for(j=0;j<strlen(a);j++)
        {
            for(k;k<strlen(b);k++)
            {
                if(a[j] == b[k])
                {
                    counter++;
                    break;
                }
            }
        }
        printf("%d\n",counter);
    }
    return 0;

}
搜索更多相关主题的帖子: possible elements 内存 sequence 
2012-06-03 18:52
glglzb
Rank: 2
等 级:论坛游民
帖 子:47
专家分:22
注 册:2011-10-12
得分:0 
回复 2楼 jokerskill
这个——只好这样了    没办法啊
2012-06-03 19:25
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:20 
最长公共子序列,经典的DP命题。基本上讲动态规划时必然会提到的例题。

你的代码跟这个题目风马牛不相及,重新学习。

重剑无锋,大巧不工
2012-06-03 20:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-370731-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.324700 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved