题目1410:垒积木 DP

题目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());  
    }  
  
}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值