青鸟_Blue_Bird @ 2020-03-04 20:16:45
常规分情况讨论,写完之后题解也参考过了,但为什么我只有30分?无论是不是调用上方函数都只有30分!求救!!
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define il inline
il int read(){
int x = 0, s = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-')s = -1;
c = getchar();
}
while(isdigit(c)){
x = x * 10 + c - '0';
c = getchar();
}
return x * s;
}
int v[N][4], p[N][4];
int f[N];
int cost2(int a, int b,int i){
return v[i][a] + v[i][b];
}
int cost3(int i){
return v[i][0] + v[i][1] + v[i][2];
}
int mul(int a, int i){
return p[i][a] * v[i][a];
}
int main(){
int n = read(), m = read();
for(int i = 1;i <= m; i++){
int v1 = read(), p1 = read(), q = read();
if(!q){
v[i][0] = v1;
p[i][0] = p1;
}
else if(!v[i][1]){
v[q][1] = v1;
p[q][1] = p1;
}
else {
v[q][2] = v1;
p[q][2] = p1;
}
}
for(int i = 1;i <= m; i++){
for(int j = n;j >= 0; j--){
if(j >= v[i][0]){//分情况讨论
f[j] = max(f[j], f[j - v[i][0]] + v[i][0]*p[i][0]);
}
if(j >= v[i][0]+v[i][1]){
f[j] = max(f[j], f[j - v[i][0] - v[i][1]] + v[i][0]*p[i][0] + v[i][1]*p[i][1]);
}
if(j >= v[i][0] + v[i][2]){
f[j] = max(f[j], f[j - v[i][0] - v[i][2]] + v[i][0]*p[i][0] + v[i][2]*p[2][0]);
}
if(j >= v[i][0] + v[i][1] + v[i][2]){
f[j] = max(f[j], f[j - (v[i][0] + v[i][1] + v[i][2])] + v[i][0]*p[i][0] + v[i][1]*p[i][1] + v[2][0]*p[i][2]);
}
}
}
printf("%d\n", f[n]);
return 0;
}
by 空与白之凌 @ 2020-03-04 20:17:27
名字好评
by 壕壕壕壕壕 @ 2020-03-04 20:18:17
名字好评++
by Karl_Aurora @ 2020-03-04 20:27:14
连某二刺螈视频网站都比我巨
by sss7020 @ 2020-03-04 20:30:07
名字和名字颜色好评