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. 孤荷凌寒自学python第五十二天初次尝试使用python读取Firebase数据库中记录

    孤荷凌寒自学python第五十二天初次尝试使用python读取Firebase数据库中记录 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数 ...

  2. 深入理解css之float

    1.float的历史 float的设计的初衷:文字环绕效果 2.包裹与破坏 增强浮动的感性认知 包裹:1.收缩 2.坚挺 3.隔绝 里面的布局和外面一点关系都没有 包裹的特性就是BFC block f ...

  3. HDU 4057 Rescue the Rabbit ( AC自动机 + 状态压缩DP )

    模板来自notonlysuccess. 模式串只有10个,并且重复出现的分值不累加,因此很容易想到状态压缩. 将模式串加入AC自动机,最多有10*100个状态. dp[i][j][k]:串长为i,在T ...

  4. hdu1712 分组背包 ACboy needs your help

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. nagios原理及配置详解

    1.Nagios如何监控Linux机器 NRPE总共由两部分组成:(1).check_nrpe插件,运行在监控主机上.服务器端安装详见:(2).NRPE daemon,运行在远程的linux主机上(通 ...

  6. role management

    role management https://panjiachen.github.io/vue-element-admin/#/permission/page

  7. [Linux]创建和启用Swap交换区

    如果你的服务器的总是报告内存不足,并且时常因为内存不足而引发服务被强制kill的话,在不增加物理内存的情况下,启用swap交换区作为虚拟内存是一个不错的选择,我购买的DigitalOcean VPS ...

  8. [洛谷P4389]付公主的背包

    题目大意:有$n(n\leqslant10^5)$种物品,第$i$个物品体积为$v_i$,都有$10^5$件.给定$m(m\leqslant10^5)$,对于$s\in [1,m]$,请你回答用这些商 ...

  9. [poj] 2074 Line of Sight || 直线相交求交点

    原题 给出一个房子(线段)的端点坐标,和一条路的两端坐标,给出一些障碍物(线段)的两端坐标.问在路上能看到完整房子的最大连续长度是多长. 将障碍物按左端点坐标排序,然后用房子的右端与障碍物的左端连线, ...

  10. 【BZOJ 2809 dispatching】

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4393  Solved: 2246[Submit][Status][Discuss] Descript ...