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 = 24005;
int n,m,k,maxn=0,ans=0;
int mx=-1;
int v[N],a[N],b[N],dp[N*N];
int main()
{scanf("%d%d",&n,&k);for(int i=1;i<=k;i++)scanf("%d",&v[i]);for(int i=1;i<=n;i++)scanf("%d",&a[i]);for(int i=1;i<=n;i++){b[i]=a[i]-max(a[i-1]-1,0);mx=max(mx,b[i]);}for(int i=1;i<=mx;i++)dp[i]=inf;for(int i=1;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]]+1);}}for(int i=1;i<=n;i++){if(dp[b[i]]==inf){printf("-1\n");return 0;}ans+=dp[b[i]];}printf("%d\n",ans);return 0;
}

转载于:https://www.cnblogs.com/jianrenfang/p/6279653.html

(寒假集训)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. DP\记忆化搜索-牛客寒假集训营3-牛牛的DRB迷宫I

    DP-牛客寒假集训营3-牛牛的DRB迷宫I 题目: 题意: 求迷宫问题的方案数量.与--求迷宫问题的方案数量.与--求迷宫问题的方案数量.与--DP题型总结中的<摘花生>类似.中的< ...

  4. 构造-牛客寒假集训营3-牛牛的DRB迷宫II

    构造-牛客寒假集训营3-牛牛的DRB迷宫II 题目: 题意: 输入一个数字,表示从起点(1,1)到终点(n,m)的方案数量,输出满足条件的迷宫.输入一个数字,表示从起点(1,1)到终点(n,m)的方案 ...

  5. 关于构造和二进制,题目:牛牛的DRB迷宫Ⅱ(源自牛客竞赛2020年寒假集训)

    关于构造和二进制,题目:牛牛的DRB迷宫Ⅱ(源自牛客竞赛2020年寒假集训) 题目: 链接:https://ac.nowcoder.com/acm/contest/3004/B 来源:牛客网 题目描述 ...

  6. 2019NEFU寒假集训新生考试 2020.1.6

    2019NEFU寒假集训新生考试 2020.1.6 为期一周的的培训终于面临尾声,就以一场考试告终吧. A 28的因子 Description 我们都知道28的因子中含有4和7,而某些人偏爱数字4和7 ...

  7. 大一寒假集训(11)(12)---map,set

    大一寒假集训(11)-map 1.查字典 nefu 1678 #include <bits/stdc++.h> using namespace std; map<string,int ...

  8. 寒假集训三(暴力枚举)2020.01.02(11题)

    寒假集训三(暴力枚举)id :521 Problem:A 二倍的问题 Description 给定2到15个不同的正整数,你的任务是计算这些数里面有多少个数对满足:数对中一个数是另一个数的两倍.比如给 ...

  9. 2023寒假集训通知

    各位家长,各位同学,新年好! 过去的2022是我们编程学习,算是比较成功的一年.大家跟着我们的团队进行了约一年的培训,很有收获.纵观全年: 1.寒假我们认真集训了24天 2.三四月间参加了人工智能学会 ...

最新文章

  1. Linux下常用的命令
  2. Mycat高可用集群搭建
  3. 服务器皮肤在哪个文件里,服务器怎么使用皮肤
  4. 【渝粤题库】陕西师范大学202011 微观经济学 作业 (专升本、高起本)
  5. PHP使用SMTP邮件服务器
  6. linux rsync 常见错误,Linux rsync常见错误
  7. 打开d盘由于这台计算机的限制,又出现限制我想打开D盘、E盘,就是打不开,电脑提示:限制本 爱问知识人...
  8. python找图是什么模块-python中模块查找的原理与方法详解
  9. JasperReports项目中的应用
  10. cstring越界_CString 内核
  11. 最小路径问题_BFS
  12. Git常见问题及报错
  13. 实例!AGV与MES对接的智能仓储系统设计
  14. 前端面试 计算机网络篇
  15. info setup 制作的安装程序 提示卸载程序出现内部错误找不到此版本的卸载程序的utCompiledCode记录
  16. css中的单位换算_关于网页中pt和px的单位换算!
  17. 文档在线编辑开发心得
  18. 软件测试原书第二版(佩腾著)-学习笔记(一)
  19. 我弟今年高考,报的志愿是电子信息,到现在录取的是计算机科学与技术,哪个专业更好一些,2021年电子信息科学与技术专业大学排名及分数线【统计表】...
  20. Windows Server 2012 R2安装并升级Exchange2010后端服务器(LZK)

热门文章

  1. 解决Hadoop运行时的WARN util. NativeCodeLoader: Unable to load native-hadoop library for your platform
  2. linux编译时开启宏,【spec】Linux上编译安装的spec文件中的常用路径以及宏变量
  3. Tex, LaTex概念及实例
  4. webrtc 判断是否支持_5G时代-WebRTC音视频高级开发
  5. java 编辑二进制文件_java写二进制文件,不能直接编辑,该怎么操作?
  6. mysql utf8存不了中文乱码_MySQL怎么存文本不乱码?
  7. Fence Repair (二叉树求解)(优先队列,先取出小的)
  8. Just a Hook(线段树区间更新)
  9. 正则提取Swagger在线文档里面的返回实体类字段
  10. JavaScript中的点击事件