Mooo Moo

时间限制: 1 Sec  内存限制: 64 MB
提交: 5  解决: 4
[提交][状态][讨论版]

题目描述

Farmer
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.

输入

* Line 1: The integers N and B.
* 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.

输出

* Line 1: The minimum number of cows owned by FJ, or -1 if there is no  configuration of cows consistent with the input.

样例输入

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 (完全背包)的更多相关文章

  1. USACO Mooo Moo

    洛谷 P2214 [USACO14MAR]哞哞哞Mooo Moo 洛谷传送门 JDOJ 2416: USACO 2014 Mar Silver 3.Mooo Moo JDOJ传送门 Descripti ...

  2. 【题解】Luogu P2214 [USACO14MAR]哞哞哞Mooo Moo

    P2214 [USACO14MAR]哞哞哞Mooo Moo 题目描述 Farmer John has completely forgotten how many cows he owns! He is ...

  3. CSU-ACM寒假集训选拔-入门题

    CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...

  4. 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] ...

  5. 中南大学2019年ACM寒假集训前期训练题集(基础题)

    先写一部分,持续到更新完. A: 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆 ...

  6. 【寒假集训系列DAY3】

    DAY2的坑之后会补上 DAY3 今天暴力分拿的还是不错的...60+30+25=115,但还是太弱了呀,每题都只会暴力(话说第3题直接输-1给了15分,本以为只会给5分,然后打了半个小时的爆搜... ...

  7. 【集训Day4 动态规划】【2018寒假集训 Day4 更新】蛙人

    蛙人 (ple) 蛙人使用特殊设备潜水.设备中有一个气瓶,分两格:一格装氧气,另一格装氮气.留在水中有时间的限制,在深水中需要大量的氧气与氮气.为完成任务,蛙人必须安排好气瓶.每个气瓶可以用它的重量和 ...

  8. P2214 [USACO14MAR]哞哞哞Mooo Moo

    链接:Miku ---------------------- 这道题还是个背包 --------------------- 首先看一下声音的组成,对于每一个农场的声音,它是由两部分组成的 :上一个农场 ...

  9. 2022寒假集训day2

    day1:学习seach和回溯,初步了解. day2:深度优化搜索 T1 洛谷P157:https://www.luogu.com.cn/problem/P1157 题目描述 排列与组合是常用的数学方 ...

随机推荐

  1. android surfaceview 入门介绍

    由于工作中需自定义控件,以前没写过. 开始时,实用view 实现了,经理说不好,担心效率低,要求每秒需要刷新10次左右. 然后,学习使用  surfaceview. 看了网上简单的Demo,找到him ...

  2. JavaScript简易学习笔记

    学习地址:http://www.w3school.com.cn/js/index.asp 文字版: https://github.com/songzhenhua/github/blob/master/ ...

  3. Kotlin中功能操作与集合(KAD 11)

    作者:Antonio Leiva 时间:Feb 2, 2017 原文链接:https://antonioleiva.com/functional-operations-collections-kotl ...

  4. 常用模块(shutil copy、压缩、解压)

    作用与功能 主要用于文件的copy,压缩,解压 导入shuitl模块: import shutil copy方法 1 1.shutil.copyfileobj()  打开file1,并copy写入fi ...

  5. Vue_自定义指令

    关于Vue的自定义指令: - 在Vue中除了核心功能默认内置的指令(v-model & v-show) - Vue也允许注册自定义指令. 注意,在 Vue2.0 中,代码复用和抽象的主要形式是 ...

  6. 课时6:Python之常用操作符

    目录: 一.算术操作符 二.优先级问题 三.比较操作符 四.逻辑操作符 五.课时06课后习题及答案 ****************** 一.算术操作符 ****************** > ...

  7. fisheye在centos上的安装

    目录 描述 部署过程 安装及配置 破解 添加存贮库 在jira上配置 描述 Fisheye 一个源代码库深度查看软件,它可以挖掘源代码库中的有用信息,呈现在Web浏览器界面上. Crucible是一个 ...

  8. BI商业智能培训系列——(三)SSAS入门

    简介:     一个客户端工具,提供了设计.创建和管理来自数据仓库的多维数据集的功能,还提供对OLAP数据客户端访问功能. 解决方案如下: 相关概念: 维度: 维度可以理解为划分依据,简单的说就是看问 ...

  9. PHP高级——抽象类与接口的区别

    在学习PHP面向对象时,都会在抽象类与接口上迷惑,作用差不多为什么还那么容易混淆,何不留一去一?但是事实上两者的区别还是很大的,如果能够很好地运用PHP的两个方法,面向对象的程序设计将会更加合理.清晰 ...

  10. [AGC011E] Increasing Numbers [数学]

    题面 传送门 思路 首先,我们观察一下上升数的性质 可以发现,它一定可以表示为最多9个全是1的数字的和 那么我们设$N$可以被表示成$k$个上升数的和,同时我们设$p_i=\underbrace{11 ...