(寒假集训)Mooo Moo (完全背包)
Mooo Moo
时间限制: 1 Sec 内存限制: 64 MB
提交: 5 解决: 4
[提交][状态][讨论版]
题目描述
John has completely forgotten how many cows he owns! He is too
embarrassed to go to his fields to count the cows, since he doesn't want
the cows to realize his mental lapse. Instead, he decides to count his
cows secretly by planting
microphones in the fields in which his cows tend to gather, figuring
that he can determine the number of cows from the total volume of all
the mooing he hears.
FJ's N fields (1 <= N <= 100) are
all arranged in a line along a long straight road. Each field might
contain several types of cows; FJ owns cows that come from B different
breeds (1 <= B <= 20), and a cow of breed i moos at a volume of
V(i) (1 <= V(i) <= 100). Moreover, there is a strong wind blowing
down the road, which carries the sound of mooing in one direction from
left to right: if the volume of mooing in some field is X, then in the
next field this will contribute X-1 to the total mooing volume (and X-2
in the field after that, etc.). Otherwise stated, the mooing volume in a
field is the sum of the contribution due to cows in that field, plus
X-1, where X is the total mooing volume in the preceding field.
Given the volume of mooing that FJ records in each field, please compute the minimum possible number of cows FJ might own.
The volume FJ records in any field is at most 100,000.
输入
* Lines 2..1+B: Line i+1 contains the integer V(i).
* Lines 2+B..1+B+N: Line 1+B+i contains the total volume of all mooing in field i.
输出
样例输入
5 2
5
7
0
17
16
20
19
样例输出
4
提示
FJ owns 5 fields, with mooing volumes 0,17,16,20,19. There are two breeds of cows; the first moos at a volume of 5, and the other at a volume of 7.There are 2 cows of breed #1 and 1 cow of breed #2 in field 2, and there is
another cow of breed #1 in field 4.
【分析】由题意知,每一个区域的声音大小除了自身外 只受上一个区域有关,减去上一个区域的影响后,就只剩下自己本身产生的声音,求最少的牛的数目,就是完全背包了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 1e3;
const int M = ;
int n,m,k,maxn=,ans=;
int mx=-;
int v[N],a[N],b[N],dp[N*N];
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=k;i++)scanf("%d",&v[i]);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++){
b[i]=a[i]-max(a[i-]-,);
mx=max(mx,b[i]);
}
for(int i=;i<=mx;i++)dp[i]=inf;
for(int i=;i<=k;i++){
for(int j=v[i];j<=mx;j++){
if(dp[j-v[i]]!=inf)dp[j]=min(dp[j],dp[j-v[i]]+);
}
}
for(int i=;i<=n;i++){
if(dp[b[i]]==inf){
printf("-1\n");
return ;
}
ans+=dp[b[i]];
}
printf("%d\n",ans);
return ;
}
(寒假集训)Mooo Moo (完全背包)的更多相关文章
- USACO Mooo Moo
洛谷 P2214 [USACO14MAR]哞哞哞Mooo Moo 洛谷传送门 JDOJ 2416: USACO 2014 Mar Silver 3.Mooo Moo JDOJ传送门 Descripti ...
- 【题解】Luogu P2214 [USACO14MAR]哞哞哞Mooo Moo
P2214 [USACO14MAR]哞哞哞Mooo Moo 题目描述 Farmer John has completely forgotten how many cows he owns! He is ...
- CSU-ACM寒假集训选拔-入门题
CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...
- HZNU-ACM寒假集训Day7小结 背包DP
背包问题 01背包 状态:f(i,j) 表示只能装前i个物品的情况下,容量为j的背包所能达到的最大总价值 状态转移方程: f(i,j)=max(f(i-1,j),f(i-1,j-w[i])+v[i] ...
- 中南大学2019年ACM寒假集训前期训练题集(基础题)
先写一部分,持续到更新完. A: 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆 ...
- 【寒假集训系列DAY3】
DAY2的坑之后会补上 DAY3 今天暴力分拿的还是不错的...60+30+25=115,但还是太弱了呀,每题都只会暴力(话说第3题直接输-1给了15分,本以为只会给5分,然后打了半个小时的爆搜... ...
- 【集训Day4 动态规划】【2018寒假集训 Day4 更新】蛙人
蛙人 (ple) 蛙人使用特殊设备潜水.设备中有一个气瓶,分两格:一格装氧气,另一格装氮气.留在水中有时间的限制,在深水中需要大量的氧气与氮气.为完成任务,蛙人必须安排好气瓶.每个气瓶可以用它的重量和 ...
- P2214 [USACO14MAR]哞哞哞Mooo Moo
链接:Miku ---------------------- 这道题还是个背包 --------------------- 首先看一下声音的组成,对于每一个农场的声音,它是由两部分组成的 :上一个农场 ...
- 2022寒假集训day2
day1:学习seach和回溯,初步了解. day2:深度优化搜索 T1 洛谷P157:https://www.luogu.com.cn/problem/P1157 题目描述 排列与组合是常用的数学方 ...
随机推荐
- 每天一个Linux命令(8):chmod命令
chmod命令用来变更文件或目录的权限. 权限范围的表示法如下: u User,即文件或目录的拥有者:g Group,即文件或目录的所属群组:o Other,除了文件或目录拥有者或所属群组之 ...
- linux部署环境配置
https://blog.csdn.net/dsczxcc/article/details/78728330
- 项目中DataTables分页插件的使用
在项目开发的过程中,一般都会对表格进行分页处理,大多是情况下会在项目中配置好后台分页插件,提高效率,减轻浏览器的压力.但是有时会遇到有些数据不能直接通过分页插件操作数据库进行分页数据查询,那就需要用到 ...
- 数据库——pymysql模块的使用(13)
1.基本用法——建立链接,获取游标,执行sql语句,关闭 建立远程链接账号和权限 mysql> grant all on *.* to '; Query OK, rows affected, w ...
- 孤荷凌寒自学python第四十一天python的线程同步之Event对象
孤荷凌寒自学python第四十一天python的线程同步之Event对象 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 鉴于Lock锁与RLock锁均宣告没有完全完成同步文件操作的问题,于 ...
- 聊聊、Mybatis XML
引入相应的依赖包 <dependency><groupId>org.mybatis</groupId><artifactId>mybatis-sprin ...
- Python——数据类型之list、tuple
本篇主要内容 • list初识 • list元素的访问 • list内部所有的方法 • tuple介绍和与list用法的比较 我觉得Python里面用的最多的就是List了,感觉好强大.他能存 ...
- CentOS 6.3 下 vsftp搭建
环境:CentOS6.3 ftp的三种用户模式 匿名用户:vsftp默认开启匿名用户,但只允许下载不允许上传:匿名用户anonymous或ftp:匿名用户目录/var/ftp,但实际上vsftp对匿名 ...
- CentOS下创建和root权限完全相同用户
新建用户 [root@bagon ~]# useradd newroot 修改密码 [root@bagon ~]# passwd newroot 编辑/etc/passwd,找到新建用户那一行 new ...
- zabbixproxy安装
目录 1 zabbix3.2安装.... 1 2 安装proxy. 1 2.1 安装zabbix-proxy. 1 2.1.1 配置zabbix yum源.... 1 2.1 ...