2 条题解

  • 0
    @ 2025-10-8 16:48:30
    #include<bits/stdc++.h>
    using namespace std;
    bool f[11000];int a[110];
    int tot[11000];
    int main()
    {
        int t;scanf("%d", &t);
        memset(tot, 0, sizeof(tot));
        for(int ti=1;ti<=t;ti++)
        {
            int x, n=0, T=0;
            while(scanf("%d", &x)!=EOF && x!=-1) a[++n] = x, T += x;
            memset(f, 0, sizeof(f));
    		f[0] = 1;
            for(int i=1;i<=n;i++)
            {
                for(int j=T;j>=a[i];j--)
                {
                    if(f[j-a[i]] == 1) f[j] = 1;
                }
            }
            for(int i=0;i<=T;i++) if(f[i]) tot[i]++;
        }
        for(int i=10000;i>=0;i--) if(tot[i]==t){printf("%d\n", i);break;}
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:48:23
      #include<bits/stdc++.h>
      using namespace std;
      bool f[11000];int a[110];
      int tot[11000];
      int main()
      {
          int t;scanf("%d",&t);
          memset(tot,0,sizeof(tot));
          for(int ti=1;ti<=t;ti++)
          {
              int x,n=0,T=0;
              while(scanf("%d",&x)!=EOF && x!=-1)a[++n]=x,T+=x;
              memset(f,0,sizeof(f));
      		f[0]=1;
              for(int i=1;i<=n;i++)
              {
                  for(int j=T;j>=a[i];j--)
                  {
                      if(f[j-a[i]]==1)f[j]=1;
                  }
              }
              for(int i=0;i<=T;i++)if(f[i])tot[i]++;
          }
          for(int i=10000;i>=0;i--)if(tot[i]==t){printf("%d\n",i);break;}
          return 0;
      }
      • 1

      *【背包:填满型01背包】多个背包一样大

      信息

      ID
      98
      时间
      1000ms
      内存
      128MiB
      难度
      5
      标签
      递交数
      219
      已通过
      86
      上传者