bzoj2298: [HAOI2011]problem a

topic link

bzoj2298: [HAOI2011]problem a

answer

The answer to complement transformation is n - the most people tell the truth
Consider each person's words to form an equal score interval
Let the number of people with the same score be the interval weight, then the problem is to find the maximum weight disjoint interval

code

/*************************************************************/
 
#include<map>
#include<vector>
#include<cstdio>
#include<cstring> 
#include<algorithm> 
inline int read() { 
    int x = 0,f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}  
    while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
    return x * f;
}  
const int maxn = 100007; 
int n; 
struct node { 
    int l;int r,size; 
    node (int l = 0,int r = 0) : l(l) , r(r) {} ;  
    bool operator  < (const node a)const {
        if(l != a.l) return l < a.l; 
        return r < a.r;
    }
} ;
std::map <node,int> Seg;
std::vector<int>vec[maxn]; 
int dp[maxn]; 
int main() { 
    n = read(); 
    for(int a,b,i = 1;i <= n;++ i)  { 
        a = read() + 1,b = read(); 
        b = n - b; node Tmp;  
        if(Seg[Tmp = node(a,b)] < b - a + 1) Seg[Tmp] ++ ;
        if(Seg[Tmp] ==  1) vec[b].push_back(a); 
    } 
    int num = 0; 
    //std::sort(peo + 1,peo + n + 1);  
    for(int i = 1;i <= n;++  i) { 
        dp[i] = dp[i - 1]; 
        for(int j = 0;j < vec[i].size();++ j) {
            int l = vec[i][j]; 
            dp[i] = std::max(dp[i],dp[l - 1] + Seg[node(l,i)]); 
        }
    }
    printf("%d\n",n - dp[n]);   
    return 0; 
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325018876&siteId=291194637