zoukankan      html  css  js  c++  java
  • caioj 1413 动态规划4:打鼹鼠

    记住一定要区分n和m分别代表什么,我已经因为这个两道题浪费很多时间了
    然后这个道题有点类似最长上升子序列n平方的做法,只是判断的条件不同而已

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #define REP(i, a, b) for(int i = (a); i < (b); i++)
    using namespace std;
    
    const int MAXN = 11234;
    int f[MAXN], n, m; 
    struct node
    {
    	int t, x, y;
    	void read() { scanf("%d%d%d", &t, &x, &y); }
    	bool operator < (const node& rhs) const
    	{
    		return t < rhs.t; 
    	}
    }a[MAXN];
    
    bool judge(int i, int j)
    {
    	return (a[j].t - a[i].t) >= abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
    }
    
    int main()
    {
    	scanf("%d%d", &n, &m);
    	REP(i, 0, m) a[i].read();
    	sort(a, a + m);
    	
    	int ans = 1;
    	f[0] = 1;
    	REP(i, 1, m)
    	{
    		f[i] = 1;
    		REP(j, 0, i)
    			if(judge(j, i))
    				f[i] = max(f[i], f[j] + 1);
    		ans = max(ans, f[i]);
    	}
    	printf("%d
    ", ans);
    
    	return 0;
    }
  • 相关阅读:
    SVG
    JavaScript的性能优化
    sublime长期使用的快捷键
    spring实现AOP
    java之spring
    JAVA面试题02
    java面试题01
    MyBatis之关联关系
    MyBatis之动态sql
    MyBatis之sql映射文件
  • 原文地址:https://www.cnblogs.com/sugewud/p/9819406.html
Copyright © 2011-2022 走看看