测试点一数据: 输入:
6:50 7:20 5
10 80 0
5 35 5
30 100 1
20 50 3
3 20 4
输出:
240
#include <bits/stdc++.h>
using namespace std;
char c1[10],c2[10];
int w[10005],c[10005],type[10005],f[1005];
int sh=0,sm=0,eh=0,em=0;
int counttime() {
int t1,t2;
t1 = eh-sh;
if(t1 == 0) t2 = em-eh;
else if(t1 == 1) t2 = 60-sm+em;
else t2 = (t1-1)*60+60-sm+em;
return t2;
}
int main() {
int n;
scanf("%d:%d %d:%d %d", &sh,&sm,&eh,&em,&n);
printf("%d %d %d %d %d\n", sh,sm,eh,em,n);
int times = counttime();
//printf("%d", times);
for(int i = 1; i <= n; i++) {
scanf("%d%d%d", &w[i],&c[i],&type[i]);
}
for(int i = 1; i <= n; i++) {
if(type[i] == 0) {
for(int j = w[i];j <= times;j++) f[j] = max(f[j],f[j-w[i]]+c[i]);
}
else if(type[i] == 1) {
for(int j = times; j>= w[i]; j--) f[j] = max(f[j],f[j-w[i]]+c[i]);
}
else {
for(int j = 1; j <= type[i]; j++) {
for(int k = times; k >= w[i]; k--) f[k] = max(f[k],f[k-w[i]]+c[i]);
}
}
}
printf("%d\n", f[times]);
return 0;
}