我原来的 ac 代码:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define Max(x,y) ((x)>(y)?(x):(y))
struct Gold{
int x,y,t,v;
bool operator < (Gold x){
return this->y * x.x < this->x * x.y;
}
bool operator == (Gold x){
return this->y * x.x == this->x * x.y;
}
Gold operator + (Gold x){
Gold tmp=*this;
if(labs(x.x)>labs(tmp.x)){
tmp.x=x.x;
}
if(labs(x.y)>labs(tmp.y)){
tmp.y=x.y;
}
tmp.t+=x.t;
tmp.v+=x.v;
return tmp;
}
}a[210];
int dp[40010];
vector<Gold>g[40010];
int main(){
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y>>a[i].t>>a[i].v;
}
sort(a,a+n);
g[0].push_back(a[0]);
int cnt=1;
for(int i=1;i<n;i++){
if(a[i]==a[i-1]){
g[cnt-1].push_back(g[cnt-1][g[cnt-1].size()-1]+a[i]);
}else{
g[cnt++].push_back(a[i]);
}
}
for(int i=0;i<cnt;i++){
for(int j=m;j>=0;j--){
for(int k=0;k<g[i].size();k++){
if(j>=g[i][k].t)dp[j]=Max(dp[j],dp[j-g[i][k].t]+g[i][k].v);
}
}
}
cout<<dp[m];
return 0;
}
但是这个样例就能让他 wa:
输入样例:
3 8
1 2 3 4
3 6 3 3
2 4 3 4
输出样例:
8
程序输出:
7
建议添加hack数据。