zoukankan      html  css  js  c++  java
  • rq160 竞赛真理 dp水题。

    水题啊水题,我老是被水题虐,果然我还是弱菜啊。。。

    明明想出动态转移方程了,是01背包的变形,分组背包下就可以了,我好像想复杂了,在循环里面各种取最大值最小值。。。

    上传上去总输出无结果,本地完全没问题的啊,我各种改数组,去头文件什么的,没有丝毫变化。。。Orz太打击人了。。。

    最后还是用分组数组A过。。。

    #include <cstdio>
    #define maxn 1080010
    int dp[maxn] = {0};
    
    inline int min(int a, int b){
    	return a > b ? b : a;
    }
    inline int max(int a, int b){
    	return a > b ? a : b;
    }
    
    int main()
    {
    	int n, t;
    	int w1, t1, w2, t2;
    	int i, j;
    	scanf("%d%d", &n, &t);
    	for (i = 1; i <= n; i++)
    	{
    		scanf("%d%d%d%d", &w1, &t1, &w2, &t2);
    		for (j = t; j >= min(t1, t2); j--)
    		{
    			if (j >= t1)
    				dp[j] = max(dp[j], dp[j - t1] + w1);
    			if (j >= t2)
    				dp[j] = max(dp[j], dp[j - t2] + w2);
    		}
    	}
    	printf("%d\n", dp[t]);
    	return 0;
    }




  • 相关阅读:
    leetcode165
    leetcode63
    leetcode92
    leetcode86
    捣鼓Haskell
    递归操作链表
    treap(堆树)
    贪心策略 — 分数背包
    LeetCode.21
    LeetCode.94
  • 原文地址:https://www.cnblogs.com/java20130723/p/3212150.html
Copyright © 2011-2022 走看看