zoukankan      html  css  js  c++  java
  • 1362. 健康的荷斯坦奶牛

    暴搜水题~ 。

    const int N=30;
    int need[N];
    int feed[20][N];
    int res[N];
    vector<int> path,ans;
    int n,m;
    
    bool check()
    {
        for(int i=1;i<=n;i++)
            if(res[i] < need[i])
                return false;
        return true;
    }
    
    void dfs(int u,vector<int> &path)
    {
        if(u > m)
        {
            if(check())
            {
                if(ans.size() == 0 || path.size() < ans.size() || (ans.size() == path.size() && path < ans))
                    ans=path;
            }
            return;
        }
    
        for(int i=1;i<=n;i++) res[i]+=feed[u][i];
        path.push_back(u);
        dfs(u+1,path);
        path.pop_back();
        for(int i=1;i<=n;i++) res[i]-=feed[u][i];
        dfs(u+1,path);
    }
    
    int main()
    {
        cin>>n;
        for(int i=1;i<=n;i++) cin>>need[i];
    
        cin>>m;
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
                cin>>feed[i][j];
    
        dfs(1,path);
    
        cout<<ans.size();
        for(int i=0;i<ans.size();i++)
            cout<<' '<<ans[i];
        cout<<endl;
        //system("pause");
        return 0;
    }
    
  • 相关阅读:
    Codeforces 1354C2
    Codeforces 1354C1
    Codeforces 1355C
    Codeforces 1353D
    Codeforces 1352
    Codeforces 1351C
    Codeforces 1344B/1345D
    Codeforces 1342D
    Codeforces 1340B/1341D
    Codeforces 1343D
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14830196.html
Copyright © 2011-2022 走看看