B - Free Market 涉及背包问题 + DP
const int INF = 1000000000; const double eps = 1e-8; const int maxn = 511010; int a[maxn]; int dp[maxn]; int main() { //freopen("in.txt","r",stdin); int n,d; while(cin>>n>>d) { repf(i,1,n) scanf("%d",&a[i]); clr(dp); dp[0] = 1; repf(i,1,n) { repd(j,50*10000,0) { if(dp[j] && j + a[i] <= 50*10000) dp[j + a[i]] = 1; } } int sum = 0,num = 0; while(1) { int flag = 0; repd(i,sum + d,sum + 1) { if(i > 50*10000) continue; if(dp[i]) { sum = i; num++; flag = 1; break; } } if(flag == 0) break; } cout<<sum<<" "<<num<<endl; } return 0; }
posted on 2013-12-01 21:22 keep trying 阅读(314) 评论(0) 编辑 收藏 举报