(寒假集训)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 题目描述 排列与组合是常用的数学方 ...
随机推荐
- 使用selenium监听每一步操作
1.创建类LogEventListener.java, 如下: package com.demo; import org.openqa.selenium.By; import org.openqa.s ...
- 一个初学者的辛酸路程-jQuery
前言: 主要概要: 1.HTML+CSS补充 2.DOM事件 3.jQuery示例 内容概要: 1.布局 代码如下 <!DOCTYPE html> <html lang=" ...
- iOS如何隐藏状态栏,包括网络标志、时间标志、电池标志等
我们在开发App的时候,在遇到有状态栏时,NavigationBar上面的按钮,是极难点击的,所以这个时候,最好我们能够人为的隐藏掉状态栏. 如果一直需要隐藏的话,直接在info.plist里面,添加 ...
- android自定义控件属性
有两种方法为自定义的控件设置属性 . 来自为知笔记(Wiz)
- java与C#对比文章阅读
文章:JAVA与C#的区别 讲了C#与java一些基本异同. 易语言官网有个表,比较了易语言.Java.C#的区别,比较全面可以借鉴.
- 虚机中访问外网;NAT中的POSTROUTING是怎么搞的?
看下docker中是怎么配置的网络 在虚机中访问外网:设定了qemu,在主机上添加路由:sudo iptables -t nat -I POSTROUTING -s 192.168.1.110 -j ...
- [C语言]防止头文件和全局变量重复定义
昨天下午将全局变量定义在H文件中导致链接时提示变量在多个obj文件内重复. 解决办法如下: 将变量移入C文件中进行定义,然后在H文件中加入extern在变量之前. 这样当其它C文件引用该全局变量时 ...
- Problem b
Problem b 题目描述 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 输入 第一行一个整数 ...
- Java中方法的重写与成员变量的隐藏
这篇文章讨论了Java面向对象概念中一个基本的概念–Field Hiding(隐藏成员变量) 在讨论这个问题之前,我们看一段特别特别简单的代码,请问一下方法的数据结果是什么? public class ...
- 图表绘制工具--Matplotlib 2
''' [课程3.] 基本图表绘制 plt.plot() 图表类别:线形图.柱状图.密度图,以横纵坐标两个维度为主 同时可延展出多种其他图表样式 plt.plot(kind='line', ax=No ...