zoukankan      html  css  js  c++  java
  • 高位前缀和,求他的子集的和https://ac.nowcoder.com/acm/contest/4784/A

    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    typedef long long ll;
    const int maxn=1e5+10;
    char s[40][maxn];
    int f[1<<21];
    
    int main()
    {
        int T;
        cin>>T;
        while(T--){
        int n,m,a,b;
        scanf("%d%d%d%d",&n,&m,&a,&b);
            for(int i=0;i<(1<<n);i++)
                f[i]=0;
        for(int i=0;i<n;i++)
            scanf("%s",s[i]);
            
        for(int i=0;i<m;i++)
        {
            int t=0;
            for(int j=0;j<n;j++)
            {
                if(s[j][i]=='*'){
                    t|=(1<<j);
                }
            }
            f[t]++;
        }
            
        for(int j = 0; j < n; j++)
            for(int i = 0; i < 1 << n; i++)
                if(i >> j & 1)
                    f[i] += f[i ^ (1 << j)];
    
        int ans=0;
        for(int i=0;i<(1<<n);i++)
        {
            int num=0;
            for(int j=0;j<n;j++)
                if((i&(1<<j))!=0)
                    num++;
            
            if(num<=a){
    //            cout<<i<<" "<<dp[i]<<endl;
                ans=max(ans,f[i]);
            }
        }
            
            if(m-ans<=b)
                cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
        
        }
        
    }
  • 相关阅读:
    作业5.1 四则运算----封装
    作业四
    作业2 (完)
    作业3
    作业二。。
    数独
    回答自己的提问
    《一个程序猿的生命周期》读后感
    阅读13-17章
    阅读10,11,12章
  • 原文地址:https://www.cnblogs.com/King-of-Dark/p/12552395.html
Copyright © 2011-2022 走看看