Codeforences Round #349 (div2)
来源:互联网 发布:怎么进入网站的数据库 编辑:程序博客网 时间:2024/05/19 17:09
【题意】给你一个字符串,然后删去前五个字符后剩下的部分能划分出几种单词来,单词的长度只能为2 or 3,注意一种划分方案中不允许出现两个连续相等的单词,很容易想到我们可以按位置枚举这些单词,然后需要用DP判断这个单词能不能被划分出来。
【分析】这里我看了本次比赛第一名的方法,确实有被惊艳到!简直就是set大暴力呀,代码相对于其他也显得很简单!
【AC代码】
#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+7;set<string>v[maxn];//用来判重setset<string>ans;//存答案的setint main(){ string s; cin>>s; int len = s.length(); for(int i=len-1; i>4; i--){ string t = s.substr(i,1); for(int j=i-1; j>=i-2&&j>4; j--){ t = s[j]+t; if (v[i + 1].size() == 1 && !v[i + 1].count(t) || v[i + 1].size() > 1 || i + 1 >= len) {v[j].insert(t);ans.insert(t);} } } cout<<ans.size()<<endl; for(auto x:ans){ cout<<x<<'\n'; } return 0;}
1 0
- Codeforences Round #349 (div2)
- Codeforences Round #PI(div2) D. One-Dimensional Battle Ships
- Codeforences #309 B (div2)
- Codeforences #309 C(div2)
- Codeforences #334 C(div2)
- Codeforences Educational Round 11
- Educational Codeforences Round 9 B
- Codeforences #307(div2) C . GukiZ hates Boxes
- Codeforences #287 div2 D. The Maths Lecture
- Codeforences #297 div2 (A,B,C,D,E)
- codeforces round #174 div2
- codeforces round 171 div2
- codeforce round 175 div2
- codeforces round# 177 div2
- Codeforces Round #185(div2)
- Codeforces round#226 div2
- codeforce round#226 div2
- codeforces round 234 DIV2
- Coins (hdu 2844)多重背包
- 『Python高级编程』学习笔记之一: 第四章——选择好的名称
- android消息机制
- redis的主从复制
- 舞伴配对问题
- Codeforences Round #349 (div2)
- 集合中打括号的替换
- Light OJ 1094 - Farthest Nodes in a Tree【树的直径 两次bfs】
- Adapter中的跳转 & Caused by:Android.util.AndroidRuntimeException
- NIO Buffer的细节
- UVa 401 Palindromes
- 关于C++中sort函数所使用的cmp函数中的&的疑惑
- jsp传参数中文乱码问题url&后台
- POJ-2594-Treasure Exploration(可重点最小路径覆盖)