Damn Couples


Time Limit: 1 Second      Memory Limit: 32768 KB

As mentioned in the problem "Couples", so many new words appear on the internet. Another special one is "Damn Couples", a club which consists of people who have failed on love affairs and decide not to start a relationship. (If you want to know more words, just turn to a search engine.)

We have a group of people in the club, and everyday they sit there in one line in a fixed order, doing nothing. Life in the club is indeed boring, especially for the leader Wyest, and one day she invented a game. She first makes up a list of imaginary "8g"s among the members, every "8g" is between two persons, then publishes the list. Each minute she chooses one "8g" from the list and announces it to be true, until all "8g"s in the list have been announced. She will not 8g the same two persons more than once.

In a single minute, the following things may happen.

1. If the two persons involved in the "8g" are sitting next to each other, one of them will speak out the "Damn couples!" slogan, then stand up and leave the table. Notice that leaving doesn't prevent him/her from possible future "8g"s. 
2. If the ith person left, the (i-1)th and the (i+1)th are considered to be next to each other.

On the other hand, Wyest wouldn't like to see people become too few since she likes it to be noisy. All the members know this, however, to show their loyalty for the club, they try to make leaving people as many as possible, based on the already announced "8g"s and those not yet to be. Wyest also knows what they're planning, so now she wants to know at most how many people can remain, if she carefully chooses the "8g" to announce each minute. Could you help her find it out?

Input

The first line of each case will contain two integers n (2 <= n <= 500) and m (0 <= m <= C(n, 2)), indicating the number of persons and the number of "8g"s in the list. People are indexed from 0 to n - 1 and they always sit in increasing order. The following m lines each contains two integers a and b, meaning a "8g" between a and b. Proceed to the end of file.

Output

For each case, print one line containing the maximum number of people that can remain in total.

Sample Input

3 2
0 1
1 2
3 1
0 2

Sample Output

1
3
思路:
1 可以把不相邻的先宣布,所以不相邻的不纳入考虑,这时只剩下相连的几片了,任务就是求这几片的某种分割使得留下的人最多,只需要分类统计,关注这些相连片的大小即可
2 因为这些点都必须是孤立的所以就直接设dp[i]为使i相互独立所需删去点数,对一个小于i的点集j,dp[i]=max(dp[i-j]+dp[j-1]+1,dp[i-j-1][j]+1)(FFF团员取最大值),那么对于所有j,Wyest取其中的最小值,也就是dp[i]=min(dp[i],max(dp[i-j]+dp[i-j]+1,dp[i-j-1][j]+1))
3 这道题如果按照我最初的思路,直接dp原图而不是分类统计,那么反而会很麻烦
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[];
int n,m;
bool heap[]; int main(){
while(scanf("%d%d",&n,&m)==){
memset(dp,,sizeof(dp));
memset(heap,,sizeof(heap));
int f,t;
for(int i=;i<m;i++){
scanf("%d%d",&f,&t);
if(t<f)swap(f,t);
if(t-f==){
heap[f]=true;
}
}
dp[]=;
dp[]=;
dp[]=;
for(int i=;i<=n;i++){
dp[i]=0x7ffffff;
for(int j=;j<i;j++){
dp[i]=min(dp[i],max(dp[j-]+dp[i-j]+,dp[j]+dp[i-j-]+));
}
}
int ans=,cnt=;
for(int i=;i<n;i++){
if(!heap[i]||i==n-){
if(cnt>) ans+=dp[cnt];
cnt=;
}
else cnt++;
}
printf("%d\n",n-ans);
}
return ;
}

ZOJ 3161 Damn Couples 动态规划 难度:2的更多相关文章

  1. Damn Couples ZOJ - 3161

    传送门 题目大意 N个人,M组关系,每次选一种关系,如果两个人相邻,则任意删除其中一个,否则不变.问最坏情况下最多能剩多少人. 分析 为了留的人最多,我们可以先将原来不相邻的关系全部说完,这样我们只需 ...

  2. [ZOJ 3662] Math Magic (动态规划+状态压缩)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3662 之前写过这道题,结果被康神吐槽说代码写的挫. 的确,那时候 ...

  3. ZOJ 1234 Chopsticks(动态规划)

    Chopsticks 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=234 题目大意:给定n个筷子的长度,取k+8套筷 ...

  4. UVa LA 3882 - And Then There Was One 递推,动态规划 难度: 2

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

  5. UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2

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

  6. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  7. ZOJ 3829 Known Notation 贪心 难度:0

    Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation ...

  8. sgu 183. Painting the balls 动态规划 难度:3

    183. Painting the balls time limit per test: 0.25 sec.memory limit per test: 4096 KB input: standard ...

  9. ZOJ ACM 1204 (JAVA)

    毕业好几年了,对算法还是比較有兴趣,所以想又一次開始做ACM题.俺做题比較任意,一般先挑通过率高的题来做. 第1204题,详细描写叙述请參考,ZOJ ACM 1204 1)难度分析 这个题目,基本的难 ...

随机推荐

  1. bzoj 3600 没有人的算术 - 替罪羊树 - 线段树

    题目都是图片,就不给了,就给链接好了 由于bzoj比较慢,就先给[vjudge传送门] 有兴趣的可以去逛bzoj[bzoj传送门] 题目大意 有n个数a[1],a[2],...,a[n],它们开始都是 ...

  2. luogu4473 BZOJ2143 2011[国家集训队]飞飞侠

    题目戳这里 有问题可以在博客@ 应该还会有人来看吧,嘻嘻 正题: 题目大意: 题目很清楚,就是一个点有一定的范围,会有一定的花费 求三个点中的任意两个点到另一个点的最小花费 (麻麻教育我千万读好题目( ...

  3. 软件设计师真题试题&&答案

    软件设计师2013上半年上午试题及答案详解 下午试题 2013下半年上午答案 试题 下午答案 试题 2014上半年上午答案 2015上半年上午答案 2016上半年上午试题

  4. 切换tab页时,tab页中的echart变形问题

    本文为博主原创,未经允许,不得转载: 在两个tab页中,分别展现了两个echart图表,同样的格式与写法,但只有在默认选中的tab页中的图表显示的是正常的, 但进入另一个tab页中时,图表则产生了变形 ...

  5. IIS Express 配置json minitype

    IIS Express 配置json minitype 1.在命令窗口中cd到IIS Express安装目录,默认是“C:\Program Files\IIS Express”: 2.在IIS Exp ...

  6. #使用ListView更新数据出现闪烁解决办法

    //使用双缓冲:添加新类继承ListView 对其重写 public class DoubleBufferListView : ListView { public DoubleBufferListVi ...

  7. python 处理命令行参数--转载

    标题写了那么久,现在现在才有时间,整理下自己的思路.首先先总结下自己对sys模块的理解.手册上对sys的描述是系统参数和系统函数,这里的系统实际上是python解释器.这个模块提供了用户可以访问的解释 ...

  8. BeautifulSoup中的find,find_all

    1.一般来说,为了找到BeautifulSoup对象内任何第一个标签入口,使用find()方法. 以上代码是一个生态金字塔的简单展示,为了找到第一生产者,第一消费者或第二消费者,可以使用Beautif ...

  9. Blue_Flke团队项目设计完善&编码测试

    任务1:文档<软件设计方案说明书>github地址:https://github.com/13993013291/ruanjianguigexuqiu 任务2:项目集成开发环境:eclip ...

  10. 8天掌握EF的Code First开发

    C#高级知识点&(ABP框架理论学习高级篇)——白金版 http://www.cnblogs.com/farb/p/ABPAdvancedTheoryContent.html