Time Limit: 1000MS | Memory Limit: 65536 | |
Description
大活附近的新楼终于造好了,包工头准备尽快打扫完工地,立刻交付工程。此时工地上有n个杂物,包工头想要先运走m个重物,但只有一辆载重量为W的卡车停在工地上,包工头想要尽可能大的利用此卡车载重能力。问这辆卡车走的时候运载了多少重量的东西?
Input
第1行:n(n<=20),m,W(W<=1000000000)
第2行:n个数,表示每个重物的重量(wi<=1000000000)。
Output
一行:卡车走的时候运载的重量,如果不能运走m个物品,则输出0。
Sample Input
1 2 3
Sample Output
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w[25],v[25];
int main()
{
int n,m,i,j,k,cont;
ll tempw,c,maxw=0;
scanf("%d%d%lld",&n,&m,&c);
for(i=0;i<n;i++){
scanf("%lld",&w[i]);
}
for(int num=0;num<1<<n;num++){
cont=0;
k=num;
tempw=0;
for(i=0;i<n;i++){
if(k%2==1){
tempw+=w[i];
cont++;
}
k=k/2;
}
if(tempw<=c&&cont==m){
if(tempw>maxw){
maxw=tempw;
}
}
}
if(maxw==0) printf("0\n");
else
printf("%lld\n",maxw);
return 0;
}