标签:int alt end cout main div get txt out
列举所有的子集找最优就行。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; const lon SZ=30,INF=0x7FFFFFFF; int v[SZ],arr[SZ][SZ]; inline int lowbit(int x) { return x&-x; } int getdgt(int x) { int res=0; for(;x;x-=lowbit(x),++res); return res; } bool chk(int x,int n) { int tmp[SZ]; memset(tmp,0,sizeof(tmp)); for(int i=0;i<31;++i) { if(x&(1<<i)) { for(int j=0;j<n;++j) { tmp[j]+=arr[i][j]; } } } for(int j=0;j<n;++j) { if(tmp[j]<v[j])return 0; } return 1; } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { int n; cin>>n; for(int i=0;i<n;++i)cin>>v[i]; int m; cin>>m; for(int i=0;i<m;++i) { for(int j=0;j<n;++j) { cin>>arr[i][j]; } } int mind=INF,res=0; for(int i=0;i<(1<<m);++i) { if(getdgt(i)<mind&&chk(i,n)) { mind=getdgt(i); res=i; } } cout<<mind; for(int i=0;i<31;++i) { if(res&(1<<i))cout<<" "<<i+1; } cout<<endl; } return 0; }
标签:int alt end cout main div get txt out
原文地址:https://www.cnblogs.com/gaudar/p/9822202.html