zoukankan      html  css  js  c++  java
  • express

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,m,s,k;
    
    void in(int &x)
    {
        char c=getchar();x=0;
        while(c<'0'||c>'9')c=getchar();
        while(c<='9'&&c>='0')x=x*10+c-'0',c=getchar();
    }
    
    void out(int x)
    {
        if(x>9)out(x/10);
        putchar(x%10+'0');
    }
    
    long long f[200010];
    
    struct tree
    {
        int c[1010];    
        int l;
        int from;
    }e[200010];
    
      bool cmp(int a,int b)
      {
          return a>b;
      }
    bool b[200010];
    long long ans,t,num;
    int kind;
    
    int main()
    {
        freopen("express.in","r",stdin);
        freopen("express.out","w",stdout);
        in(n),in(m),in(s),in(k);
        for(int i=1;i<=m;i++)
        {
            in(kind),in(e[kind].c[++e[kind].l]);
            e[kind].c[e[kind].l]-=2;
        }
        for(int i=1;i<=n;i++)
        sort(e[i].c+1,e[i].c+e[i].l+1,cmp);
        for(int i=1;i<=n;i++)
        {
            t=0;
            for(int j=1;j<=e[i].l;j++)
            {
                t+=e[i].c[j];
                if(t>=k)
                {
                    s-=j;
                    e[i].from=j+1;
                    ans+=t;
                    break;
                }
            }
            if(t<k||s<0)
            {
                cout<<"-23333333";
                return 0;
            }
        }
        for(int i=1;i<=n;i++)
          for(int z=e[i].from;z<=e[i].l;z++)
           for(int j=s;j>=1;j--)
            f[j]=max(f[j],f[j-1]+e[i].c[z]);
             cout<<f[s]+ans;
        return 0;
    }
  • 相关阅读:
    c++看题
    理想化
    thin mission
    编程时 和 thinking
    tiny mission 2021 10 20
    A Magic Lamp HDU
    Poj 3370
    鸽巢原理(抽屉原理)
    Miller-Rabin质数测试
    Nim or not Nim? HDU
  • 原文地址:https://www.cnblogs.com/war1111/p/7534994.html
Copyright © 2011-2022 走看看