Damn Couples

原创 2018年04月15日 12:04:12

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.)

Damn couples!

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

Hint

In the first case, no matter in what order the "8g"s are announced, the 1st person wouldn't leave first. In the second case, the 0th person and the 2nd person didn't sit together, so all of the three remain.


#include<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

const int N=500+10;

int dp[N],vis[N][N];

void init(){
    dp[0]=0;dp[1]=dp[2]=dp[3]=1;
    for(int i=4;i<N;i++)
    for(int j=1;j<i;j++)
    dp[i]=max(dp[i],min(dp[j-1]+dp[i-j],dp[j]+dp[i-j-1]));
}

int main(){
    //freopen("in.txt","r",stdin);
    init();
    int m,n;
    while(~scanf("%d%d",&n,&m)){
        memset(vis,0,sizeof(vis));
        for(int i=0;i<m;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            //if(abs(x-y)!=1)continue;
            vis[x][y]=vis[y][x]=1;
        }
        int cnt=1;int ans=0;
        for(int i=0;i<n;i++){

            if(vis[i][i+1])cnt++;
            else{
                ans+=dp[cnt];
                cnt=1;
            }
            //cout<<i<<" "<<cnt<<endl;
        }
        printf("%d\n",ans);
    }
    //fclose(stdin);
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ujn20161222/article/details/79948059

ZOJ3161 Damn Couples

As mentioned in the problem "Couples", so many new words appear on the internet. Another special one...
  • C20142407
  • C20142407
  • 2015年08月13日 19:41
  • 323

Damn Couples ZOJ - 3161

考虑一串相邻的关系 设f[i]为有i个人的时候最多剩下的人 那么转移就为 f[ i ] = max( f[ i ] , min ( f[ i-j ] + f[ j-1 ] , f[ i-j-1 ...
  • cys460714380
  • cys460714380
  • 2018年03月28日 13:59
  • 16

1121. Damn Single (25)解题报告

直接一对一哈希。 如果没有单身狗,第二行为空。 #define _CRT_SECURE_NO_WARNINGS #include #include struct couple { int ...
  • chr1991
  • chr1991
  • 2017年01月01日 10:43
  • 458

765. Couples Holding Hands

N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum numb...
  • zjucor
  • zjucor
  • 2018年01月14日 16:12
  • 445

Damn Vulnerable Linux

 http://www.damnvulnerablelinux.org/
  • cnbird2008
  • cnbird2008
  • 2009年10月09日 09:15
  • 767

开始学习web安全 & 搭建 Damn Vulnerable Web App 渗透测试平台

今天在查相关学习web安全资料的时候看到了一个词。。“蜜罐”。。。我初二的时候就知道这词了,前阵子重新开始学渗透的时候竟然没意识到,还是自己好好多搭几个本地测试来测试吧...不然坐等查水表... ...
  • qq794858207
  • qq794858207
  • 2014年05月31日 20:39
  • 1608

1121. Damn Single 解析

夫妇两人都来了才算,单一个人来还是算单身狗。。。做个题都要被虐。。。嘤嘤嘤。。 不过这次才知道map到int里面没有的元素会被默认为0。 #include #include #include #...
  • sheepyWYY
  • sheepyWYY
  • 2017年03月14日 10:34
  • 130

LWC 67: 765. Couples Holding Hands

LWC 67: 765. Couples Holding Hands 传送门:765. Couples Holding Hands Problem: N couples sit in 2N...
  • u014688145
  • u014688145
  • 2018年01月14日 16:44
  • 576

poj2752 Seek the Name, Seek the Fame--------KMP

Seek the Name, Seek the Fame Time Limit:2000MS Memory Limit:65536K Tota...
  • qiqijianglu
  • qiqijianglu
  • 2012年08月10日 13:43
  • 2133

765-Couples Holding Hands

Description: N couples sit in 2N seats arranged in a row and want to hold hands. We want to know th...
  • LaputaFallen
  • LaputaFallen
  • 2018年03月24日 13:04
  • 27
收藏助手
不良信息举报
您举报文章:Damn Couples
举报原因:
原因补充:

(最多只允许输入30个字)