woj 1005 Holding Animals

2024-02-06 06:32
文章标签 animals holding 1005 woj

本文主要是介绍woj 1005 Holding Animals,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一个简单的背包问题。dp

/** Author: stormdpzh* Created Time: 2012/7/11 21:23:48* File Name: woj_1005.cpp*/
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, a, b) for(int i = a; i >= b; i--)
#define out(n) printf("%d\n", n)
#define mset(a, b) memset(a, b, sizeof(a))
#define wh(n) while(1 == scanf("%d", &n))
#define whz(n) while(1 == scanf("%d", &n) && n != 0)
#define lint long longusing namespace std;const int MaxN = 105;
const int MaxS = 100005;int s[MaxN], p[MaxN];
int dp[MaxS];
int n, ts;void init()
{mset(dp, 0);rep(i, n) scanf("%d%d", &s[i], &p[i]);scanf("%d", &ts);
}int gao()
{rep(i, n) repd(v, ts, 0) {if(v - s[i] >= 0)dp[v] = max(dp[v], dp[v - s[i]] + p[i]);}return dp[ts]; 
}int main()
{wh(n) {init();out(gao());}return 0;
}


这篇关于woj 1005 Holding Animals的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/683418

相关文章

HDU 1005(矩阵乘法)

A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). 题意:给出一个递推公式,求第N项。 题解:开始试图找出一个能够直接算的递

代码随想录Day 28|题目:122.买卖股票的最佳时机Ⅱ、55.跳跃游戏、45.跳跃游戏Ⅱ、1005.K次取反后最大化的数组和

提示:DDU,供自己复习使用。欢迎大家前来讨论~ 文章目录 题目题目一:122.买卖股票的最佳时机 II贪心算法:动态规划 题目二:55.跳跃游戏解题思路: 题目三: 45.跳跃游戏 II解题思路方法一方法二 题目四:1005.K次取反后最大化的数组和解题思路 总结 贪心算法继续刷题 题目 题目一:122.买卖股票的最佳时机 II 122. 买卖股票的最佳时机 II 贪心

算法训练第24天|122.买卖股票的最佳时机II|55. 跳跃游戏|45.跳跃游戏II|1005.K次取反后最大化的数组和

LeetCode 122.买卖股票的最佳时机II 题目链接:122.买卖股票的最佳时机II 题目讲解:代码随想录 func maxProfit(prices []int) int {var sum intfor i := 1; i < len(prices); i++{if prices[i] - prices[i - 1] > 0{sum += prices[i] - prices[i

代码随想录算法训练营day28 | 贪心算法 | 122.买卖股票的最佳时机 II、55.跳跃游戏、45.跳跃游戏 II、1005.K次取反后最大化的数组和

文章目录 122.买卖股票的最佳时机 II思路 55.跳跃游戏思路解法1解法2 45.跳跃游戏 II思路 1005.K次取反后最大化的数组和思路 总结 今天是贪心算法专题的第二天,直接上题目 122.买卖股票的最佳时机 II 题目链接:122. 买卖股票的最佳时机 II - 力扣(LeetCode) 思路 思想很简单:把所有的涨幅都赚到,把所有的跌幅都躲过,最后就能获

URAL 1005 Stone Pile

这种题型: Balanced Partition    刚开始用的方法:    从最大的开始放,每次放到数量较小的那一堆上,最后看相差为多少。    这样很容易想,可惜是错的,反例如下。    5  10 9 8 7 2   如果这么算,分的是 (10,7) 和 (9,8,2)  相差2    而最小的答案是(10,8)和(9,7,2)  相差0     看了这

小山菌_代码随想录算法训练营第三十天|122.买卖股票的最佳时机II、55. 跳跃游戏 、45.跳跃游戏II、1005.K次取反后最大化的数组和

122.买卖股票的最佳时机II 文档讲解:代码随想录.买卖股票的最佳时机II 视频讲解:贪心算法也能解决股票问题!LeetCode:122.买卖股票最佳时机II 状态:已完成 代码实现 class Solution {public:int maxProfit(vector<int>& prices) {int result = 0;for (int i = 1; i < prices

Redis:WRONGTYPE Operation against a key holding the wrong kind of value

1.错误信息 redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value 2.分析 当前程序中key的操作类型,并不与redis库中存在的key的类型相匹配。举例  第一次保存key,将其设置为key-value

【PAT】【Advanced Level】1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a non-negative integer N, your task is to compute the sum of all the

Another app is currently holding the yum lock; waiting for it to exit...

Linux安装Redis依赖遇到的问题 Another app is currently holding the yum lock; waiting for it to exit… 解决办法 sudo rm -f /var/run/yum.pid sudo: 以超级用户(root)的权限执行后续命令。某些操作需要管理员权限才能执行,因此需要使用 sudo。rm: Linux/Unix

【代码随想录算法训练营第三十五天|1005.K次取反后最大化的数组和、134.加油站、135.分发糖果】

文章目录 1005.K次取反后最大化的数组和134.加油站135.分发糖果 1005.K次取反后最大化的数组和 把数组先排序,排序好后根据k和数组长度中最小的那个进行遍历,目的是如果有负数的就把他们从小到大依次取正,然后按照还剩下的k的数量来判断,如果是偶数则按照当前数组输出,如果是奇数则需要把当前数组的最小值取反再求和。 class Solution:def largestS