题意:给出n条发言,让你求最大的交流长度并输出标记顺序。

析:这个题要知道的是,前面的人是不能at后面的人,只能由后面的人at前面的,那就简单了,我们只要更新每一层的最大值就好,并不会影响到其他层。

最后再从这 n 层中取出最大值,在更新时,也可以记录着最大值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <sstream>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 5e4 + 5;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
map<string, P> mp;
int dp[maxn], pre[maxn]; void print(int pos){
if(!pre[pos]){ printf("%d", pos); return; }
print(pre[pos]);
printf(" %d", pos);
} int main(){
while(scanf("%d", &n) == 1){
string line, s;
getchar();
mp.clear();
for(int i = 1; i <= n; ++i){
getline(cin, line);
stringstream ss(line);
ss >> s;
string str = s.substr(0, s.size()-1);
dp[i] = 1, pre[i] = 0;
while(ss >> s){
if(!mp.count(s) || s == str) continue;
if(mp[s].first + 1 > dp[i]){
dp[i] = mp[s].first + 1;
pre[i] = mp[s].second;
}
}
if(mp[str].first < dp[i]) mp[str] = P(dp[i], i);
} int ans = 0, pos;
for(int i = 1; i <= n; ++i)
if(dp[i] > ans) ans = dp[i], pos = i;
printf("%d\n", ans);
print(pos);
printf("\n"); }
return 0;
}

UVaLive 6680 Join the Conversation (DP)的更多相关文章

  1. UVALive 6680 Join the Conversation

    题意:conversion的定义是下一句提到上一句的人的名字.请你输出最长的对话的长度,及组成对话的序列号. 思路:动态规划的思想很容易想到,当前句子,根据所有提到的人的名字为结尾组成的对话长度来判断 ...

  2. UVALive 4261——Trip Planning——————【dp+打印路径】

    Trip Planning Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...

  3. UVALive 6491 You win! 状态DP

    这个题目上周的对抗赛的,美国2013区域赛的题目,上次比赛真惨,就做出一道题,最多的也只做出两道,当时想把这题做出来,一直TLE. 这个题目用挂在Hunnu OJ的数据可以过,但UVALive上死活过 ...

  4. UVaLive 7143 Room Assignment (组合数+DP)

    题意:有 n 个客人,m个房间,每个房间可住ci个人,这 n 个人中有 t 对双胞胎,sum{ci}  = n 问你有多少种住房方法. 析:计数DP,dp[i][j] 表示前 i 个房间,还剩下 j ...

  5. UVALive 4987---Evacuation Plan(区间DP)

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UVALive 5066 Fire Drill --BFS+DP

    题意:有一个三维的地图,有n个人被困住,现在消防队员只能从1楼的一个入口进入,营救被困者,每一个被困者有一个价值,当消防队员找到一个被困者之后,他可以营救或者见死不救,如果救的话,他必须马上将其背到入 ...

  7. UVALive 7276 Wooden Signs (DP)

    Wooden Signs 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/E Description http://7xjob4. ...

  8. uvalive 5721 Activation (概率dp+方程)

    题目链接:http://vjudge.net/problem/viewProblem.action?id=24999 主要思想就是解方程的思想. 二维dp应该很容易想到,就是当前位置加队伍长度. dp ...

  9. UVALive 6672 Bonus Cards 概率dp

    题意呢 就是有两种售票方式 一种是icpc 一种是其他方式 icpc抢票成功的概率是其他方式的2倍…… 这时 一个人出现了 他通过内幕知道了两种抢票方式各有多少人 他想知道自己如果用icpc抢票成功的 ...

随机推荐

  1. Vue如何使用vue-awesome-swiper实现轮播效果

    在Vue项目中如何实现轮播图的效果呢,在传统项目中第一个想到的一般都是swiper插件,代码简单好用.一开始我也是直接npm安装swiper然后照着之前的传统写法写,然而却没有效果,只会显示图片但没有 ...

  2. 数据导出Excel,动态列

    今天碰到一个需求,要求将用户回答的问卷及问题导出Excel表格,问卷对应的问题数量不一致,需要动态添加列表头,简单记录. 要导出Excel需要添加poi.jar包 用户-问卷实体(固定列): pack ...

  3. Mac 共享无线网络

    dock栏启动『设置』进入下一步.   进入设置后,点击『共享』进入下一步.   进入共享后 1.选择左边框中『互联网共享』,就会看到截图右边的样子 2.『共享以下来源链接』一项选择『以太网』(默认应 ...

  4. JDBC--JAVA数据库连接相关

    JDBC API提供了以下接口和类: DriverManager: 这个类管理数据库驱动程序的列表.确定内容是否符合从Java应用程序使用的通信子协议正确的数据库驱动程序的连接请求.识别JDBC在一定 ...

  5. [TyvjP1050] 最长公共子序列(DP)

    传送门 f[i][j] 表示第 1 个串匹配到第 i 位,第 2 个串匹配到第 j 位的答案. f[i][j] = max(f[i - 1][j], f[i][j - 1])    (a[i] != ...

  6. [NOIP2007] 普及组

    奖学金 模拟 开个struct排序即可 c++吼啊 /*by SilverN*/ #include<algorithm> #include<iostream> #include ...

  7. 静态区间第k大(划分树)

    POJ 2104为例[经典划分树问题] 思想: 利用快速排序思想, 建树时将区间内的值与区间中值相比,小于则放入左子树,大于则放入右子树,如果相等则放入左子树直到放满区间一半. 查询时,在建树过程中利 ...

  8. Apache 使用localhost(127.0.0.1)可以访问,使用本机IP(局域网)不能访问

    本机ip是:192.168.1.25,输入后提示: Forbidden You don't have permission to access / on this server 对于此问题的解决办法, ...

  9. ios截屏事件监听

    目的:实现截屏反馈,类似支付宝的截屏上传反馈功能. 1.注册全局通知,在Appdelegate中注册截屏监听通知 - (void)registNotification{ [[NSNotificatio ...

  10. Linux system log avahi-daemon[3640]: Invalid query packet.

    2014-06-11 Check the Linux system log find the errorr: Jun  9 11:18:49 hostname avahi-daemon[3640]: ...