给一个算LCS时得到的DP矩阵,然后根据这个矩阵让你算出两个符合条件的字符串

因为字符串长度<=25,然后可以先假设A字符串就是abcdef....,然后根据A算B就行,看B中哪个跟A一样,但是A中可能有两个或以上的字符跟B的某个是一样的,然后这时就要把这两个变成同一个,但是这个涉及到很多,因为可能还跟B中别的字符一样,所以就 用并查集维护他们,把他们并到一个集合里,最后输出时按集合的根输出就行。

或者不用并查集,每次遇到这 个问题时,就把AB字符串都扫一遍,遇到要改的改掉就行,反正长度 25,随便搞

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
#define ll long long
int R, C;
char A[30], B[30];
int DP[30][30];
int set[30];
int stk[30];
int findset(int x)
{if (x == set[x])return x;elsereturn set[x] = findset(set[x]);
}
void unionset(int x, int y)
{int fx = findset(x);int fy = findset(y);if (fx == fy)return;elseset[fy] = fx;findset(y);
}
int main()
{//freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);scanf("%d%d", &R, &C);for (int i = 0; i <= R; ++i){for (int j = 0; j <= C; ++j){scanf("%d", &DP[i][j]);}}for (int i = 1; i <= R; ++i){A[i] = 'a' + i - 1;set[i] = i;}int cnt = 0;for (int j = 1; j <= C; ++j){cnt = 0;for (int i = 1; i <= R; ++i){if (DP[i][j] > DP[i - 1][j] && DP[i][j] > DP[i][j - 1]){stk[cnt++] = i;}}for (int i = 1; i < cnt; ++i)unionset(stk[0], stk[i]);}for (int i = 1; i <= R; ++i){findset(i);}for (int i = 1; i <= R; ++i)A[i] = A[findset(i)];for (int i = 1; i <= C; ++i){if (B[i] == 0)B[i] = 'z';}for (int j = 1; j <= C; ++j){cnt = 0;for (int i = 1; i <= R; ++i){if (DP[i][j] > DP[i - 1][j] && DP[i][j] > DP[i][j - 1]){B[j] = A[set[i]];}}}printf("%s\n", A + 1);printf("%s\n", B + 1);//system("pause");//while (1);return 0;
}

CodeForces Gym 100989B LCS (B)相关推荐

  1. Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks

    Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...

  2. Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)

    Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...

  3. [Codeforces Gym 101651/100725B] Banal Tickets

    Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...

  4. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  5. Codeforces Gym 100269 Dwarf Tower (最短路)

    题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game na ...

  6. Codeforces Gym 100676G Training Camp 状压dp

    http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修 ...

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  9. Codeforces Gym 100650B Countdown (离线)

    题目链接:http://codeforces.com/gym/100650 根据给出的树和d,求出一些结点,这些结点形成子树的第d层结点数应该尽量多,具体要求可以参考题目. dfs一个结点前保存询问深 ...

最新文章

  1. gem是什么证书_什么是GIA钻石?
  2. Teach Yourself Drupal in 24 Minutes –Minute7 使用CCK和Image
  3. 点击lable标出现下拉搜索框及选择功能
  4. 智能计算机科学的奠基人,【编注】神经网络算法奠基人之一沃尔特·皮茨的传奇故事...
  5. 解决“无法找到运行搜索助理需要的一个文件”
  6. 创建windows azure 云服务
  7. 使用Jmeter压力测试工具测试
  8. 按一行一行的方法将一个文本文件复制到另一个文件中_命令行技巧:分割文件内容...
  9. sap运维要做哪些工作_患上腰椎间盘突出,适合做哪些工作?不适合做哪些工作?...
  10. Go 触发 GC 的时机有哪些?能手动触发吗?
  11. 【转】android开发中如何结束所有的activity
  12. 用DSA或者RSA进行加密或者数字签名
  13. 【快速测试】TF02-i-CAN通过CAN分析仪与电脑通信操作教程
  14. java读写yml文件
  15. 微软云游戏服务器,微软:云游戏服务Project xCloud将扩展游戏服务的数量和地区...
  16. 数据挖掘入门必看的几个问题
  17. java并发包JUC
  18. OpenCV 书稿:前言
  19. 壹连科技冲刺深交所:年营收14亿 65%收入来自宁德时代
  20. 读《一个人的朝圣》| 沾染上称为信仰的东西,都会不一样

热门文章

  1. 制作一个古诗词的html,徐汉峰笔迹2136.诗词高手制作出万能词汇表.
  2. insert插入语句
  3. java学习--装饰器设计模式
  4. 360路由器插件_主打游戏加速 360安全路由P4C体验
  5. 详解rails命令行
  6. appvlv中偶有不爽
  7. ssm 基于微信小程序美容理发店预约系统app
  8. 群晖NAS入门(一)
  9. 服务之星网络评选视频投票小程序如何进行视频投票免费公众号投票
  10. overleaf word count 字数统计 报错 解决办法