题目1410:垒积木
时间限制:3 秒
内存限制:32 兆
特殊判题:否
提交:834
解决:188
-
题目描述:
-
给你一些长方体的积木,问按以下规则能最多垒几个积木。
1 一个积木上面最多只能垒另一个积木。
2 在下面的积木的长宽高要大于或等于上面的积木的长宽高
-
输入:
-
输入有多组,每组输入第一行是一个整数n(1<=n<=1000000),接下来n行的每行包括三个整数l,w,h(1 <= w,l,h <= 100),表示积木的长宽高。
-
输出:
-
对于每组输入,输出按规则最多能垒几个积木。
-
样例输入:
-
35 2 14 2 13 3 131 5 15 1 12 2 2
-
样例输出:
-
2
-
1
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
new Task().solve() ;
}
}
class Task{
InputReader in = new InputReader(System.in) ;
PrintWriter out = new PrintWriter(System.out) ;
int[][][] cnt = new int[101][101][101] ;
int[][][] dp = new int[101][101][101] ;
void solve(){
while(in.hasNext()){
int n = in.nextInt() ;
for(int i = 1 ; i <= 100 ; i++){
for(int j = 1 ; j <= 100 ; j++){
Arrays.fill(cnt[i][j] , 0) ;
Arrays.fill(dp[i][j] , 0) ;
}
}
while(n-- > 0) cnt[in.nextInt()][in.nextInt()][in.nextInt()]++ ;
int res = 0 ;
for(int i = 1 ; i <= 100 ; i++){
for(int j = 1 ; j <= 100 ; j++){
for(int k = 1 ; k <= 100 ; k++){
dp[i][j][k] = Math.max(dp[i-1][j][k] , dp[i][j-1][k]) ;
dp[i][j][k] = Math.max(dp[i][j][k] , dp[i][j][k-1]) + cnt[i][j][k] ;
res = Math.max(res , dp[i][j][k]) ;
}
}
}
out.println(res) ;
//out.flush();
}
out.flush();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = new StringTokenizer("");
}
private void eat(String s) {
tokenizer = new StringTokenizer(s);
}
public String nextLine() {
try {
return reader.readLine();
} catch (Exception e) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
}