POJ 2250 Compromise (UVA 531)
LCS问题。基金会DP。
我很伤心WA非常多。就在LCS问题,需要记录什么路。
反正自己的纪录path错误,最后,就容易上当。
没有优化,二维阵列,递归打印,cin.eof() 来识别 end of file 标识。
至于单词用map 映射的。
事实上也用不着,直接二维string或者 二维char 然后strcmp 也行。
Special Judge
交 UVA 531 奇怪的PE了。
。。 然后改成 flag 标记 输出 空格。最终都AC了。
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<bitset>
#include<vector>
#include<cmath> #define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOR_(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define sf scanf
#define pf printf
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define acfun std::ios::sync_with_stdio(false) #define SIZE 1000 +1
using namespace std; int a[SIZE],b[SIZE];
int dp[SIZE][SIZE];
int path[SIZE][SIZE];
map<string,int>word;
map<int,string>exword;
bool flag;
void print(int i,int j)
{
if(i>0&&j>0)
{
if(path[i][j]==0)
{
print(i-1,j-1);
if(flag)
cout<<" ";
else
flag=1;
cout<<exword[a[i-1]];
}
else if(path[i][j]==1)
print(i-1,j);
else if(path[i][j]==-1)
print(i,j-1);
}
}
int main()
{
acfun;
while(1)
{
string tmp;
word.clear();
int cot=1;
int la=0,lb=0;
flag=0;
while(1)
{
cin>>tmp;
if(cin.eof())return 0;
if(tmp=="#")break;
if(word[tmp]==0)
{
word[tmp]=cot++;
exword[cot-1]=tmp;
}
a[la++]=word[tmp];
}
while(1)
{
cin>>tmp;
if(tmp=="#")break;
if(word[tmp]==0)
{
word[tmp]=cot++;
exword[cot-1]=tmp;
}
b[lb++]=word[tmp];
}
FOR(i,0,la)
FOR(j,0,lb)
{
if(a[i]==b[j])
{
dp[i+1][j+1]=dp[i][j]+1;
path[i+1][j+1]=0;
}
else
{
if(dp[i+1][j]>=dp[i][j+1])
{
dp[i+1][j+1]=dp[i+1][j];
path[i+1][j+1]=-1;
}
else
{
dp[i+1][j+1]=dp[i][j+1];
path[i+1][j+1]=1;
}
}
}
//cout<<dp[la][lb]<<endl;
print(la,lb);
cout<<endl;
}
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ 2250 Compromise (UVA 531)的更多相关文章
- POJ - 2250 Compromise (LCS打印序列)
题意:给你两个单词序列,求出他们的最长公共子序列. 多组数据输入,单词序列长度<=100,单词长度<=30 因为所有组成LCS的单词都是通过 a[i] == b[j] 更新的. 打印序列的 ...
- POJ 2250 Compromise(LCS)
POJ 2250 Compromise(LCS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#proble ...
- POJ 3279 Fliptile(翻格子)
POJ 3279 Fliptile(翻格子) Time Limit: 2000MS Memory Limit: 65536K Description - 题目描述 Farmer John kno ...
- POJ - 3308 Paratroopers(最大流)
1.这道题学了个单词,product 还有 乘积 的意思.. 题意就是在一个 m*n的矩阵中,放入L个敌军的伞兵,而我军要在伞兵落地的瞬间将其消灭.现在我军用一种激光枪组建一个防御系统,这种枪可以安装 ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- POJ 1015 Jury Compromise(dp坑)
提议:在遥远的国家佛罗布尼亚,嫌犯是否有罪,须由陪审团决定.陪审团是由法官从公众中挑选的.先随机挑选n个人作为陪审团的候选人,然后再从这n个人中选m人组成陪审团.选m人的办法是:控方和辩方会根据对候选 ...
- POJ 3259 Wormholes (Bellman_ford算法)
题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- poj 1364 King(差分约束)
题意(真坑):傻国王只会求和,以及比较大小.阴谋家们想推翻他,于是想坑他,上交了一串长度为n的序列a[1],a[2]...a[n],国王作出m条形如(a[si]+a[si+1]+...+a[si+ni ...
随机推荐
- Linux下select, poll和epoll IO模型的详解
http://blog.csdn.net/tianmohust/article/details/6677985 一).Epoll 介绍 Epoll 可是当前在 Linux 下开发大规模并发网络程序的热 ...
- Enthought科学计算,数据分析
Enthought Canopy: Easy Python Deployment Plus Integrated Analysis Environment for Scientific Computi ...
- php使用http请求头实现文件下载
众所周知php对http协议的依赖特别强,像java或者asp.net在某些情况下可以不依赖http例如asp.net的winform,对php来说文件下载可以使用http的请求头加上php的IO就可 ...
- PS中模式算法
详见地址:http://www.68ps.com/zt/cs5/hh_zhengpian.htm
- POJ 2151 Check the difficulty of problems (动态规划-可能DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4522 ...
- 阿里巴巴2015研究project普通笔试题,与答案
欢迎您对这篇文章的其他建议.我可以留言在以下平台. 个人博客网站:www.anycodex.com/blog/ Csdn博客网站:http://my.csdn.net/?ref=toolbar 微博: ...
- ZOJ 1610 间隔染色段树
要长8000仪表板.间染色的范围,问:最后,能看到的颜色,而且颜色一共有段出现 覆盖段 数据对比水 水可太暴力 段树: #include "stdio.h" #include ...
- git配置流程
写的比较简略,主要是记录一下,以后配置别的机器的时候看一下,仅供参考. 1 安装 命令依赖包 sudo apt-get install git-core git-gui git-doc 2 设置SSH ...
- zoj3329(概率dp)
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 题意:有三个骰子,分别有k1,k2,k3个面. 每次掷骰子,如 ...
- NEU月赛Segment Balls(线段树)
问题 D: Segment Balls 时间限制: 1 Sec 内存限制: 128 MB 提交: 253 解决: 37 题目描述 Small K has recently earn money i ...