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;
    }
  • 相关阅读:
    简单 dp 题选做
    UVa11327
    Codeforces Round #641 (div.2) 题解
    新博客
    数位dp的学习
    stl粗略用法
    cf437C The Child and Toy
    poj1995 Raising Modulo Numbers
    Tarjan的学习
    最短路模板
  • 原文地址:https://www.cnblogs.com/sugewud/p/9819406.html
Copyright © 2011-2022 走看看