首页 > 其他 > 详细

1362. 健康的荷斯坦奶牛

时间:2021-05-31 11:39:50      阅读:12      评论:0      收藏:0      [点我收藏+]

暴搜水题~ 。

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;
}

1362. 健康的荷斯坦奶牛

原文:https://www.cnblogs.com/fxh0707/p/14830196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!