light oj 1013 迷之ac...我不知道为什么不re

Yes, you are developing a ‘Love calculator’. The software would be quite complex such that nobody could crack the exact behavior of the software.

So, given two names your software will generate the percentage of their ‘love’ according to their names. The software requires the following things:

  1. The length of the shortest string that contains the names as subsequence.
  2. Total number of unique shortest strings which contain the names as subsequence.

Now your task is to find these parts.

Input
Input starts with an integer T (≤ 125), denoting the number of test cases.

Each of the test cases consists of two lines each containing a name. The names will contain no more than 30 capital letters.

Output
For each of the test cases, you need to print one line of output. The output for each test case starts with the test case number, followed by the shortest length of the string and the number of unique strings that satisfies the given conditions.

You can assume that the number of unique strings will always be less than 263. Look at the sample output for the exact format.

Sample Input
Output for Sample Input
3
USA
USSR
LAILI
MAJNU
SHAHJAHAN
MOMTAJ
Case 1: 5 3
Case 2: 9 40
Case 3: 13 15

算了,,,,先上代码吧

#include<memory.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
string q,w;
int dp1[35][35];
long long dp2[90][35][35];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin>>T;
    int u=0;
    while(T--)
    {
        memset(dp1,0,sizeof(dp1));
        memset(dp2,0,sizeof(dp2));
        cin>>q>>w;
        int q1=q.size();
        int w1=w.size();
        for(int a=q1-1;a>=0;a--)
        {
            for(int b=w1-1;b>=0;b--)
            {
                if(q[a]==w[b])dp1[a][b]=dp1[a+1][b+1]+1;
                else dp1[a][b]=max(dp1[a+1][b],dp1[a][b+1]);
            }
        }
        dp2[0][0][0]=1;
        int chang=w1+q1-dp1[0][0];
        for(int a=0;a<chang;a++)
        {
            for(int b=0;b<=q1;b++)
            {
                for(int c=0;c<=w1;c++)
                {
                    if (dp2[a][b][c])  
                    {
                        if(q[b]==w[c])
                        {
                            dp2[a+1][b+1][c+1]+=dp2[a][b][c];
                        }
                        else
                        {
                            dp2[a+1][b+1][c]+=dp2[a][b][c];
                            dp2[a+1][b][c+1]+=dp2[a][b][c];
                        }
                    }

                }
            }
        }
        cout<<"Case "<<++u<<": "<<chang<<" "<<dp2[chang][q1][w1]<<endl;
    }
    return 0;
}

讲道理,我不知道这个代码为什么能ac
一开始是xjb按照LCS的套路乱写的
最后竟然a了
但是我不知道为什么不re
最后的比较明明就是超过了字符串的长度….
他为什么过了…
我真的不懂….

道理就是他吧自己当前的种数传给可能到达的一切状态….

可是他为什么a过去了啊为什么?!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值