uvalive 6680 - Join the Conversation 动态规划
来源:互联网 发布:程序员编程语言 编辑:程序博客网 时间:2024/04/30 04:41
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4692
这个题真是汗死了,训练赛的时候我看这个题快看了三个小时,题意到最后还是觉得没有理解,结果看人别人写的就是一个dp而已。
题意: 要找到一个最大的集合,包含最多的行数。如果后面的行的正文部分 包含前面行 的作者,那么这两句话可以放到一个集合里。
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<cctype>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI 3.1415926535897932384626#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)#define lson num<<1,le,mid#define rson num<<1|1,mid+1,ri#define MID int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)#define mk make_pair#define _f first#define _s secondusing namespace std;//const int INF= ;typedef long long ll;//const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);const int INF =0x3f3f3f3f;const int maxn=50000+20 ;//const int maxm= ;int n;int dp[maxn],pre[maxn];string s,message,name,word;map<string ,pair<int ,int > >mp;vector<int > ve;int main(){ while(~scanf("%d",&n)) { getchar(); mp.clear(); for(int i=1;i<=n;i++) { getline(cin,s); stringstream message(s); message>>name; name=name.substr(0,name.length()-1); dp[i]=1; pre[i]=-1; while(message>>word) { if(!mp.count(word)||word==name) continue; if(mp[word]._f+1>dp[i]) dp[i]=mp[word]._f+1,pre[i]=mp[word]._s; } if(!mp.count(name ) ) mp[name]=mk(dp[i],i); if(dp[i]>mp[name]._f) mp[name]._f=dp[i],mp[name]._s=i; } int p=1,maxi=1; for(int i=1;i<=n;i++) { if(dp[i]>maxi ) maxi=dp[i],p=i ; } ve.clear(); while(~p) { ve.push_back(p ); p=pre[p]; } printf("%d\n",ve.size()); if(ve.size()==0) continue; for(int i=ve.size()-1;i>=1;i--) { printf("%d ",ve[i]); } printf("%d\n",ve[0]); } return 0;}
0 0
- uvalive 6680 - Join the Conversation 动态规划
- UVALive 6680 Join the Conversation
- UVALive 6680Join the Conversation
- UVALive 6680 Join the Conversation (DP)
- Join the Conversation
- 1880: Join the Conversation
- UVALIVE 3637 The Bookcase <dp + 动态规划>
- UVALive 6680-动态规划dp
- UVALive - 7527 Funfair (动态规划)
- UVALive 5737|Pills|动态规划
- UVALive 6177|HDU 4489|The King's Ups and Downs|动态规划
- [UvaLive 6756] Increasing Shortest Path [动态规划]
- 【暑假】[深入动态规划]UVAlive 3983 Robotruck
- UVALive 6117 (LA 6117) Pole Arrangement 动态规划
- 【暑假】[深入动态规划]UVAlive 4794 Sharing Chocolate
- hdu1081To The Max【动态规划】
- 1163 The Triangle 动态规划
- 动态规划【 Testing the CATCHER】
- 【读书笔记】iOS网络-错误处理的经验法则
- DevExpress的gridcontrol中列自定义数据类型和算法
- Matlab与C++混合编程,添加OpenCV库
- Linux命令之dos2unix - 将DOS格式文本文件转换成UNIX格式
- 树和二叉树——二叉树遍历的递归算法
- uvalive 6680 - Join the Conversation 动态规划
- 查看文件(或文件夹)被哪个进程使用【文件已在另一程序中打开】
- Android 请求码与结果码
- 傅立叶变换中的时间和频率
- 关于EditText禁止输入空格的方法
- 【Oracle】11gR2 RAC增加interconnect网卡冗余
- js escape unescape
- Linux命令整理--mkdir命令
- 第9周实践项目3 稀疏矩形的三元组表示的实现