标签:hang ++ i++ image main cin += pac sum
_________________________________________________________________________________________________
usaco上的状压质量都好高啊QAQ
结合了二分查找,前缀和,以及dp状态的巧妙确立
————————————————————————————————————————————————————————————
#include<bits/stdc++.h> using namespace std; int n,k,ans=-1,coin[30],dp[(1<<16)+5],sum[101000]; int find(int val) { int l=1,r=n,po=0; while(l<=r){ int mid=(l+r)/2; if(sum[mid]<=val){l=mid+1,po=mid;} else r=mid-1; } return po; } int calc(int val) { int an=0; for(int i=0;i<k;i++) if(!(val&(1<<i)))an+=coin[i]; return an; } int main() { cin>>k>>n; for(int i=0;i<k;i++)cin>>coin[i]; for(int i=1;i<=n;i++){cin>>sum[i];sum[i]+=sum[i-1];} for(int i=0;i<=(1<<k)-1;i++) for(int j=0;j<k;j++) if(i&(1<<j)) dp[i]=max(dp[i],find(sum[dp[i^(1<<j)]]+coin[j])); for(int i=0;i<=(1<<k)-1;i++) if(dp[i]==n) ans=max(ans,calc(i)); cout<<ans; }
P3092 [USACO13NOV]没有找零No Change
标签:hang ++ i++ image main cin += pac sum
原文地址:https://www.cnblogs.com/SFWR-YOU/p/11285798.html