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. 【Theory of Generalization】林轩田机器学习基石

    紧接上一讲的Break Point of H.有一个非常intuition的结论,如果break point在k取到了,那么k+1, k+2,... 都是break point. 那么除此之外,我们还 ...

  2. Percona-Tookit工具包之pt-slave-find

      Preface       If we want to check out how many slaves in our replication environment.We can execut ...

  3. Jmeter微信小程序接口测试

    最近公司新项目组开发一款微信小程序电商平台,为了更好保证产品质量,因此提出了需要进行接口测试. 从接口本身来讲,对其测试与其他项目应该是一样的.所以不难理解,我们要对小程序的接口测试需要准备的 材料有 ...

  4. 孤荷凌寒自学python第六十天在windows10上搭建本地Mongodb数据服务

     孤荷凌寒自学python第六十天在windows10上找搭建本地Mongodb数据服务 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第六天.成功在本地搭建了windows ...

  5. 系统编程--高级IO

    1.非阻塞I/O 非阻塞I/O使我们可以调用不会永远阻塞的I/O操作,例如open,read和write.如果这种操作不能完成,则立即出错返回,表示该操作如继续执行将继续阻塞下去.对于一个给定的描述符 ...

  6. 在.net2.0中实现Action和Func方法

    由于这两个是在.net3.5中新加入的特性,所以我们需要自己写一下. 格式如下: delegate void Action();        delegate void Action<T, T ...

  7. P4160 [SCOI2009]生日快乐

    题目描述 windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕. 现在包括windy,一共有 N 个人来分这块大蛋糕,要求每个人必须获得相同面积的蛋糕. win ...

  8. [SCOI2005]互不侵犯 (状压$dp$)

    题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 位国王,且最后一位状态为 \(k\) . 然后就可以很轻松的转移了 ...

  9. MAC中如何配置两套android-sdk环境

    1 背景介绍 随着android studio的完善和普及,越来越多Android app开发者从Eclipse+ADT环境转到Android Studio(后文统一用AS表示).但是,AS往往需要较 ...

  10. MFC 屏幕截图(libjpeg bmp转jpg)

    项目中需要用到的功能. void Screenshot() { CDC *pDC; pDC = CDC::FromHandle(GetDC(GetDesktopWindow())); if(pDC = ...