zoukankan      html  css  js  c++  java
  • Light OJ 1013 Love Calculator

    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

    3

    USA

    USSR

    LAILI

    MAJNU

    SHAHJAHAN

    MOMTAJ

    Sample Output

    Case 1: 5 3

    Case 2: 9 40

    Case 3: 13 15

    详解:http://www.cnblogs.com/chenchengxun/p/4903430.html

    好难啊,DP。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 typedef long long ll;
     7 
     8 int n,m;
     9 ll dp[65][35][35];
    10 char s1[50],s2[50];
    11 
    12 void solve(int t){
    13     memset(dp,0,sizeof(dp));
    14     for(int i=0;i<=n;i++) dp[i][i][0]=1;
    15     for(int i=0;i<=m;i++) dp[i][0][i]=1;
    16     for(int l=0;l<n+m;l++){
    17         for(int i=0;i<n;i++){
    18             for(int j=0;j<m;j++){
    19                 if(s1[i]==s2[j]) dp[l+1][i+1][j+1]+=dp[l][i][j];            //因为相同,所以放一个字母就行
    20                 else dp[l+1][i+1][j+1]+=dp[l][i+1][j]+dp[l][i][j+1];        //要么放s1[i],要么放s2[j]
    21             }
    22         }
    23     }
    24     for(int i=1;i<=n+m;i++) if(dp[i][n][m]) { printf("Case %d: %d %lld
    ",t,i,dp[i][n][m]); break; }
    25 }
    26 
    27 int main()
    28 {   int kase;
    29     cin>>kase;
    30     for(int t=1;t<=kase;t++){
    31         scanf("%s%s",s1,s2);
    32         n=strlen(s1),m=strlen(s2);
    33         solve(t);
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    SQL Server 简单事务学习
    C# TreeView,递归循环数据加载到treeView1中
    javascript;Jquery;获取JSON对象,无刷新分页,异步加载,异步删除,实例。
    jquery获取当前页面的URL信息
    java的数据类型相关知识点
    java 图书馆初级编写
    1.1 弹出窗口控制
    轮播图片切换(函数传参)
    商品计算
    js中的作用域
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7306793.html
Copyright © 2011-2022 走看看