网易雷火笔试第四题,求解(未解)
#include<iostream>
#include<cmath>
#include<algorithm>
#include<memory>
#include<string.h>
using namespace std;
int a[105][1005];
int maxh = 0;
int n, h;
struct node{
int x, y, z;
}b[105];
void dfs(int i,int hp ,int sp) {
if (i >= n || hp <= 0)return;
if (sp <= a[i][hp])return;
if (sp > a[i][hp])a[i][hp] = sp;
if (maxh < sp)maxh = sp;
dfs(i + 1, hp - b[i].x, sp + b[i].y);
dfs(i + 1, hp - b[i].z, sp);
}
int main() {
for (int i = 0; i < 101; i++)
for (int j = 0; j < 1001; j++)
a[i][j] = -1;
cin >> n >> h;
for (int i = 0; i < n; i++) {
cin >> b[n-i-1].x >> b[n-i-1].y >> b[n-i-1].z;
}
dfs(0, h, 0);
cout << maxh << endl;
}//这是小弟的代码,才疏学浅,感觉问题不大,可是过不了,如有大佬路过,请不吝赐教,还有吐槽雷火:问为什么样例下,x,y,z>100,回,请自行思考,呵呵!
#include<cmath>
#include<algorithm>
#include<memory>
#include<string.h>
using namespace std;
int a[105][1005];
int maxh = 0;
int n, h;
struct node{
int x, y, z;
}b[105];
void dfs(int i,int hp ,int sp) {
if (i >= n || hp <= 0)return;
if (sp <= a[i][hp])return;
if (sp > a[i][hp])a[i][hp] = sp;
if (maxh < sp)maxh = sp;
dfs(i + 1, hp - b[i].x, sp + b[i].y);
dfs(i + 1, hp - b[i].z, sp);
}
int main() {
for (int i = 0; i < 101; i++)
for (int j = 0; j < 1001; j++)
a[i][j] = -1;
cin >> n >> h;
for (int i = 0; i < n; i++) {
cin >> b[n-i-1].x >> b[n-i-1].y >> b[n-i-1].z;
}
dfs(0, h, 0);
cout << maxh << endl;
}//这是小弟的代码,才疏学浅,感觉问题不大,可是过不了,如有大佬路过,请不吝赐教,还有吐槽雷火:问为什么样例下,x,y,z>100,回,请自行思考,呵呵!