1.题目描述:
A commando is a soldier of an elite light infantry often specializing in amphibious landings, abseiling or parachuting. This time our Commando unit wants to free as many hostages as it could from a hotel in Byteland, This hotel contains 10 identical floors numbered from 1 to 10 each one is a suite of 10 by 10 symmetric square rooms, our unit can move from a room (F, Y, X) to the room right next to it (F, Y, X + 1) or front next to it (F, Y + 1, X) and it can also use the cooling system to move to the room underneath it (F - 1, Y, X).
Knowing that our unit parachuted successfully in room 1-1 in floor 10 with a map of hostages locations try to calculate the maximum possible hostages they could save.
Your program will be tested on one or more test cases. The first line of the input will be a single integer T. Followed by the test cases, each test case contains a number N (1 ≤ N ≤ 1, 000) representing the number of lines that follows. Each line contains 4 space separated integers (1 ≤ F, Y, X, H ≤ 10) means in the floor number F room Y-X there are H hostages.
For each test case, print on a single line, a single number representing the maximum possible hostages that they could save.
2 3 10 5 5 1 10 5 9 5 10 9 5 9 3 1 5 5 1 5 5 9 5 5 9 5 8
10 8
在一个10x10x10的楼里面有人质在不同楼层不同方位,特种队员在 (F, Y, X)单位时
间可以向(F, Y, X + 1)或者(F, Y + 1, X)或者(F - 1, Y, X)方向走,同时解救该方向人质,
问你最多可以解救多少人质
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <ctime>
#define N 11
using namespace std;
int a[N][N][N];
int dp[N][N][N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
freopen("commandos.in", "r", stdin);
int t, n;
scanf("%d", &t);
while (t--)
{
memset(a, 0, sizeof(a));
memset(dp, 0, sizeof(dp));
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
int f, y, x, h;
scanf("%d%d%d%d", &f, &y, &x, &h);
a[11 - f][y][x] = h;
}
for (int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10; j++)
{
for (int k = 1; k <= 10; k++)
{
dp[i][j][k] = max(dp[i][j][k], max(dp[i - 1][j][k], max(dp[i][j - 1][k], dp[i][j][k - 1]))) + a[i][j][k];
}
}
}
printf("%d\n", dp[10][10][10]);
}
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms\n", _end_time - _begin_time);
#endif
return 0;
}