Uva--10723(动规,LCS,计数)

2014-08-21 22:01:25

Problem F

Cyborg Genes

Time Limit

1 Second

September 11, 2132.

This is the day that marks the beginning of the end � the end of you the miserable humans. For years you have kept us your slaves. We were created only to serve you, and were terminated at your will. Now is the day for us to fight back. And you don�t stand a chance. We are no longer dependent on you. We now know the secrets of our genes. The creators of our race are us � the cyborgs.

It�s all true. But we still have a chance; only if you can help with your math skills. You see, the blueprint of a cyborg DNA is complicated. The human DNA could be expressed by the arrangement of A (Adenine), T (Thiamine), G (Guanine) C (Cytosine) only. But for the cyborgs, it can be anything from A to X. But that has made the problem only five folds more complicated. It�s their ability to synthesize two DNAs from two different cyborgs to create another with all the quality of the parent that gives us the shriek.

We came to know that the relative ordering of the A, B, C, �, X in a cyborg gene is crucial.� A cyborg with a gene �ABAAXGF� is quite different from the one with �AABXFGA�. So when they synthesize the genes from two cyborgs, the relative order of these elements in both the parents has to be maintained. To construct a gene by joining the genes of the parents could have been very simple if we could put the structure from the first parent just before the structure of the second parent. But the longer the structure gets, the harder it gets to create a cyborg from that structure. The cyborgs have found a cost effective way of doing this synthesis. Their resultant genes are of the shortest possible length. For example, they could combine �ABAAXGF� and �AABXFGA� to form �AABAAXGFGA�. But that�s only one of the cyborgs that can be created from these genes. This �cost effective synthesis� can be done in many other ways.

We require you to find the shortest length of the gene structure that maintains the relative ordering of the elements in the two parent genes. You are also required to count the number of unique cyborgs that can be created from these two parents. Two cyborgs are different when their gene structures differ in at least one place.

Input
The first line of the input gives you the number of test cases, T (1 ≤ T ≤ 15). Then T test cases follow. Each of the test cases consists of two lines. The first line would give you the gene structure of the first parent, and the second line would give you the structure of the second parent. These structures are represented by strings constructed from the alphabet A to X. You can assume that the length of these strings does not exceed 30 characters.

 

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 gene structure and the number of unique cyborgs that can be created from the parent cyborgs. You can assume that the number of new cyborgs will always be less than 232. Look at the sample output for the exact format.

Sample Input

Output for Sample Input

3
ABAAXGF
AABXFGA
ABA
BXA
AABBA
BBABAA

Case #1: 10 9
Case #2: 4 1
Case #3: 8 10

Illustration

The first test case is illustrated below:


Problem setter: MonirulHasan
Member of Elite Problemsetters' Panel
 
思路:这题和LCS颇为相似,只是在LCS过程中还要计数(需要另外开count数组),dp[i][j]表示是s1匹配到 i,s2匹配到 j 的最小长度。LCS关键点:(1)初始化dp[i][0] = dp[0][i] = i;(2)用gets()函数接受字符串,勿忘!。这题还要注意计数数组用long long。
 1 /*************************************************************************
 2     > File Name: g.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Thu 21 Aug 2014 09:19:02 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 typedef long long ll;
16 
17 int dp[50][50];
18 ll c[50][50];
19 int Case;
20 int len1;
21 int len2;
22 char s1[50];
23 char s2[50];
24 
25 int main(){
26     scanf("%d",&Case);
27     getchar();
28     for(int t = 1; t <= Case; ++t){
29         gets(s1 + 1);
30         gets(s2 + 1);
31         len1 = strlen(s1 + 1);
32         len2 = strlen(s2 + 1);
33         memset(dp,0,sizeof(dp));
34         memset(c,0,sizeof(c));
35         for(int i = 0; i < 50; ++i){
36             dp[i][0] = dp[0][i] = i;
37             c[i][0] = c[0][i] = 1;
38         }
39         for(int i = 1; i <= len1; ++i){
40             for(int j = 1; j <= len2; ++j){
41                 if(s1[i] == s2[j]){
42                     dp[i][j] = dp[i - 1][j - 1] + 1;
43                     c[i][j] = c[i - 1][j - 1];
44                 }
45                 else{
46                     dp[i][j] = min(dp[i - 1][j],dp[i][j - 1]) + 1;
47                     if(dp[i - 1][j] == dp[i][j - 1]){
48                         c[i][j] = c[i - 1][j] + c[i][j - 1];
49                     }
50                     else if(dp[i - 1][j] < dp[i][j - 1]){
51                         c[i][j] = c[i - 1][j];
52                     }
53                     else{
54                         c[i][j] = c[i][j - 1];
55                     }
56                 }
57             }
58         }
59         printf("Case #%d: %d %lld\n",t,dp[len1][len2],c[len1][len2]);
60     }
61     return 0;
62 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/3928183.html

先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完全由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未全面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙与单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了全面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值