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 ...
随机推荐
- Andoid java文件中的Log检查工具
AndroidLogChecker 由于发布软件版本的时候我们需要把Log注释掉,此工具可以检查java类中的Log所在行以及是否已经注释. Github: https://github.com/cu ...
- Codeforces 731F Video Cards
题意:给定n个数字,你可以从中选出一个数A(不能对该数进行修改操作),并对其它数减小至该数的倍数,统计总和.问总和最大是多少? 题解:排序后枚举每个数作为选出的数A,再枚举其他数, sum += a[ ...
- bootstrap学习笔记<十一>(导航条)
基础导航条.样式:class="navbar navbar-default",属性:role="navigation" <div class=" ...
- python的最最最最最基本语法(2)
函数的定义: 使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 当用return 返回多个值时,返回的其实是一个tuple, ...
- HTML5Canvas标签
- git使用技巧
git使用技巧 转载自:http://172.17.144.8/iceway.zhang/shares/201604/201604_git_tips.md.html 我们在工作中几乎每天都会用到git ...
- jpeg了解
JPEG是一个压缩标准,又可分为标准 JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支持最高级 别的压缩,不过,这种压缩是有损耗的 ...
- 青云的机房组网方案(简单+普通+困难)(虚树+树形DP+容斥)
题目链接 1.对于简单的版本n<=500, ai<=50 直接暴力枚举两个点x,y,dfs求x与y的距离. 2.对于普通难度n<=10000,ai<=500 普通难度解法挺多 ...
- ios中javascript直接调用oc代码而非通过改变url回调方式(转)
之前一个ios项目中,需要通过UIWebview来打开一个静态页面,并在静态页面中 调用相关object-c代码. 一.以前使用js调用object-c的方法 关于如何使用javascript调用ob ...
- linux runlevel
Linux系统有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆运行级别2:多 ...