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 ...
随机推荐
- Java I/O 文件加锁,压缩
文件加锁: 文件加锁机制允许我们同步访问某个作为共享资源的文件. public class Test { public static void main(String[] args) throws I ...
- vector的插入、lower_bound、upper_bound、equal_range实例
对于这几个函数的一些实例以便于理解: #include <cstdlib> #include <cstdio> #include <cstring> #includ ...
- javascript知识总汇
命名: 变量名和函数命名:第一个单词小写以后每个单词首字母大写.geteElementById() 对象命名:每个单词首字母大写. 数据类型 typeof()方法返回数据类型. number数据类型: ...
- DDL之操作表
DDL之操作表 DDL是数据定义语言,用来定义数据库对象:数据库.表.列等.其中定义数据库我们已经在DDL之操作数据库中详细讲解了,今天我们来学习使用DDL操作表. 1.创建表 使用数据定义语言创建表 ...
- MediaPlayer的生命周期
- Web服务器异常问题记录
1.使用命令,出现"-bash: 命令: Input/output error" 重启服务器后正常,网上查了下是说硬盘写入读取异常,经过和服务器厂商沟通后,确认是硬件问题导致(硬盘 ...
- VirtualBox的网络配置,Host Only+NAT方式 (zhuan)
http://blog.csdn.net/xinghun_4/article/details/7969894 ***************************************** 其实网 ...
- HBase启动和停止命令
启动HBase集群: bin/start-hbase.sh 单独启动一个HMaster进程: bin/hbase-daemon.sh start master 单独停止一个HMaster进程: bin ...
- hiho1091_clicker背包问题
问题 类似有限背包问题,题目链接:clicker 实现 #include<stdio.h> #include<cmath> #include<iostream> # ...
- iOS开发 仿淘宝,京东商品详情3D动画
- (void)show { [[UIApplication sharedApplication].windows[0] addSubview:self.projectView]; CGRect fr ...