UVALive 6680 Join the Conversation
题意:conversion的定义是下一句提到上一句的人的名字。请你输出最长的对话的长度,及组成对话的序列号。
思路:动态规划的思想很容易想到,当前句子,根据所有提到的人的名字为结尾组成的对话长度来判断当前name的最长对话长度。每个名字需要记录它形成最长对话的长度及此时出现的行数。
想说的是,C++处理起来好优雅。Cplusplusdeeplover.
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <sstream>
#define maxn 50010
#include <map>
using namespace std; int dp[maxn], pre[maxn];
string mess, word, name, str; map<string, pair<int, int> >mp; bool ok; void print(int num) {
if (num == -1) return;
print(pre[num]);
if (ok) {
printf("%d", num+1);
ok = false;
}
else printf(" %d", num+1);
return;
} int main() {
//freopen("in.cpp", "r", stdin);
int n;
while(cin >> n) {
getchar();
mp.clear();
for (int i=0; i<n; ++i) {
getline(cin, str);
//cout << str << "...\n";
stringstream mess(str);
mess >> name;
name = name.substr(0, name.length()-1);
dp[i] = 1;
pre[i] = -1;
while(mess>>word) {
if (!mp.count(word) || word == name) continue;
if (mp[word].first + 1 > dp[i]) {
dp[i] = mp[word].first + 1;
pre[i] = mp[word].second;
}
}
if (!mp.count(name)) mp[name] = make_pair(dp[i], i);
if (mp[name].first < dp[i]) mp[name].first = dp[i], mp[name].second = i;
} int maxdp = -1, pos;
ok = true;
for (int i=0; i<n; ++i) {
if (maxdp < dp[i]) {
maxdp = dp[i];
pos = i;
}
}
cout << maxdp << endl;
print(pos);
cout << endl;
}
return 0;
}
UVALive 6680 Join the Conversation的更多相关文章
- UVaLive 6680 Join the Conversation (DP)
题意:给出n条发言,让你求最大的交流长度并输出标记顺序. 析:这个题要知道的是,前面的人是不能at后面的人,只能由后面的人at前面的,那就简单了,我们只要更新每一层的最大值就好,并不会影响到其他层. ...
- chrome49 新特性 chrome.org转载
Transitioning from SPDY to HTTP/2 Thursday, February 11, 2016 Last year we announced our intent to e ...
- DEEP LEARNING WITH STRUCTURE
DEEP LEARNING WITH STRUCTURE Charlie Tang is a PhD student in the Machine Learning group at the Univ ...
- 写出完美论文的十个技巧10 Tips for Writing the Perfect Paper
10 Tips for Writing the Perfect Paper Like a gourmet meal or an old master painting, the perfect col ...
- The Sorrows of Young Werther
The Sorrows of Young Werther J.W. von Goethe Thomas Carlyle and R.D. Boylan Edited by Nathen Haskell ...
- The 2013 South America/Brazil Regional Contest 题解
A: UVALive 6525 cid=61196#problem/A" style="color:blue; text-decoration:none">Atta ...
- ML.NET is an open source and cross-platform machine learning framework
https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet Machine Learning made for ...
- video conference s/w
CamFrogWindows | Mac OS | Linux (Server only) | iOS | Android | Windows PhoneCamFrog lets you set up ...
- jms版本
Java消息服务是一个在 Java标准化组织(JCP)内开发的标准(代号JSR 914). 2001年6月25日,Java消息服务发布JMS 1.0.2b,2002年3月18日Java消息服务发布 1 ...
随机推荐
- jquery animate 改变元素背景颜色
通过animate不能直接设置css样式可以通过https://cdnjs.cloudflare.com/ajax/libs/jquery-color/2.1.2/jquery.color.min.j ...
- 《易货》Alpha版本项目展示
一.团队成员和个人博客地址 PM:董元财 开发人员:胡亚坤,董元财,刘猛 测试人员:益西多吉,马汉虎 团队名:bestRW 团队博客地址:http://www.cnblogs.com/niceRW/ ...
- iOS - UIActionSheet
前言 NS_CLASS_DEPRECATED_IOS(2_0, 8_3, "UIActionSheet is deprecated. Use UIAlertController with a ...
- c++操作io常见命令
用c++练习下 系统常见io命令. 1)显示文档的文本 2)统计文本单词数字 3)列出目录所有文件 ,递归思路 4)查找第一个匹配的字符. 5)文本单词排序, 快速排序,其实还是递归思路 6)文本单词 ...
- HIHO线段树(成段)
#include <stdio.h> #define lson l,mid,id<<1 #define rson mid+1,r,id<<1|1 ; ],lazy[ ...
- poj3855Blast the Enemy!(多边形重心)
链接 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- css+JS实现遮罩弹框
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta nam ...
- cublas相关的知识
下面链接给出了一个例子,怎么用cublas进行矩阵的运算提速,也说明了cublas的大致的使用方法. http://www.cnblogs.com/scut-fm/p/3756242.html cub ...
- Spring Boot 以 jar 包方式运行在后台
spring-boot jar 包方式启动: 首先,为了防止和常用的 Tomcat 8080 端口冲突,将 Spring-boot 项目的端口号设置为 9090. 具体方法:在 application ...
- 在Eclipse中设置Java类上面的注释(包含作者、日期等)
希望在Eclipse中,让Java类上面的注释像下面这样,改如何设置呢? 在Eclipse中,点击菜单中的Window-->Preferences,打开如下窗口: