#include#include #include #include #include #include #define NUM 1001 using namespace std; int charaNum[NUM] ;//存放输入数据的数组 int tempArr[NUM]; struct load { int weight; int index; }arr[NUM]; int x[NUM]; bool cmp(const load & a, const load & b) { return a.weight =A[i].weight) { cleft-=A[i].weight; sum++; x[A[i].index] = 1; i++; } return sum; } int main() { freopen("in.txt","r",stdin); int weight ; int num; while(cin>>weight>>num) { memset(x,0 ,sizeof(x)); for(int i= 0;i >arr[i].weight; arr[i].index=i; } stable_sort(arr,arr+num,cmp); int sum = greedySelect(arr,num,weight); if(sum == 0) { cout<<"No answer!"< 输入:
50 3 40 10 40 37 5 10 30 24 35 40 25 3 30 40 50输出:
2
1 2
2
1 3
No answer!