https://www.luogu.org/problem/show?pid=2639 题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H (5 <= H <= 45,000)公斤的干草. Bessie只能吃一整捆干草:当她开始吃一捆干草的之后就再也停不下来了.她有一个完整的N (1 <= N <= 500)捆可以给她当作晚餐的干草的清单.她自然想要尽量吃到更…
题目传送门 这也是个01背包,只是装的很... #include<bits/stdc++.h> #define MAXN 45010 using namespace std; int f[MAXN],w[MAXN],c[MAXN],n,v; int main(){ scanf("%d%d",&v,&n); ;i<=n;i++) scanf("%d",&w[i]); ;i<=n;i++) for(int j=v;j>…
题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H (5 <= H <= 45,000)公斤的干草. Bessie只能吃一整捆干草:当她开始吃一捆干草的之后就再也停不下来了.她有一个完整的N (1 <= N <= 500)捆可以给她当作晚餐的干草的清单.她自然想要尽量吃到更多的干草.很自然地,每捆干草只能被吃一次(即使在列表中相同的重量可能出现2次,但是这表示…
题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H (5 <= H <= 45,000)公斤的干草. Bessie只能吃一整捆干草:当她开始吃一捆干草的之后就再也停不下来了.她有一个完整的N (1 <= N <= 500)捆可以给她当作晚餐的干草的清单.她自然想要尽量吃到更多的干草.很自然地,每捆干草只能被吃一次(即使在列表中相同的重量可能出现2次,但是这表示…
题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H (5 <= H <= 45,000)公斤的干草. Bessie只能吃一整捆干草:当她开始吃一捆干草的之后就再也停不下来了.她有一个完整的N (1 <= N <= 500)捆可以给她当作晚餐的干草的清单.她自然想要尽量吃到更多的干草.很自然地,每捆干草只能被吃一次(即使在列表中相同的重量可能出现2次,但是这表示…
题目传送门 这题和01背包最大的区别在于它没有价值,所以我们可以人工给它赋一个价值,由于要求体积最大,把价值赋成体积即可.顺带一提,这题数据范围很大,二维会MLE,要压缩成一维才可以AC 下面给出参考程序: #include<iostream> using namespace std; ],v[],w[]; int main() { cin>>n>>m; ;i<=m;i++) { cin>>v[i]; w[i]=v[i]; } ;i<=m;i++…
P2376 [USACO09OCT]津贴Allowance 题目描述 作为创造产奶纪录的回报,\(Farmer\) \(John\)决定开始每个星期给\(Bessie\)一点零花钱. \(FJ\)有一些硬币,一共有\(N(1<=N<=20)\)种不同的面额.每一个面额都能整除所有比它大的面额. 他想用给定的硬币的集合,每个星期至少给\(Bessie\)某个零花钱的数目\(C(1<=C<=100000000)\).请帮他计算他最多能支付多少个星期的零花钱. 输入输出格式 输入格式:…
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer's land. He raises delicious papaya fruit, which is a delicacy for cows. The papaya jungle is partitioned into a grid of squares with R rows and C col…
P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll 题目描述 Bessie looks out the barn door at the beautiful spring day and thinks to herself, 'I'd really like to enjoy my walk out to the pastures for the tender spring grass.' She knows that once she leaves the b…
P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed 题目描述 Farmer John has always done his best to keep the pastures full of luscious, delicious healthy grass for the cows. He has lost the battle, though, as the evil milkweed has attained a foothold…
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer's land. He raises delicious papaya fruit, which is a delicacy for cows. The papaya jungle is partitioned into a grid of squares with R rows and C col…
题目描述 The cows enjoy mooing at the barn because their moos echo back, although sometimes not completely. Bessie, ever the excellent secretary, has been recording the exact wording of the moo as it goes out and returns. She is curious as to just how mu…
题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H ( <= H <= ,)公斤的干草. Bessie只能吃一整捆干草:当她开始吃一捆干草的之后就再也停不下来了.她有一个完整的N ( <= N <= )捆可以给她当作晚餐的干草的清单.她自然想要尽量吃到更多的干草.很自然地,每捆干草只能被吃一次(即使在列表中相同的重量可能出现2次,但是这表示的是两捆干草,其中每…
P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to delive…
https://www.luogu.org/problem/show?pid=2957 题目描述 The cows enjoy mooing at the barn because their moos echo back, although sometimes not completely. Bessie, ever the excellent secretary, has been recording the exact wording of the moo as it goes out a…
题目描述 Bessie's cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive integers I (1 <= I <= 10^60) for which Bessie must determine their parity (explained in second grade as 'Even... or odd?'). Bessie is overwhelmed by the…
题目传送门 这道题实际非常简单好奇是怎么变黄的... 其实也就是一个SPFA,本人非常懒,不想打邻接表,直接用矩阵就好啦... #include<bits/stdc++.h> using namespace std; ][],m,fr,to; void add(int x,int y,int z){a[x][y]=z;} ]; ]; queue<int> q; void SPFA(int from){ vis[; q.push(; while(!q.empty()){ ; q.po…
https://www.luogu.org/problemnew/show/P2376 看了题解做的,根本不会贪心.. #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back t…
题目链接:https://www.luogu.org/problemnew/show/P1339 解题思路: 一道简单的最短路水题,dijkstra解法模板思路:https://www.cnblogs.com/lipeiyi520/p/10340361.html AC代码: #include<bits/stdc++.h> using namespace std; const int ff=0x3f3f3f; ][],a,b,c; ]; ]; void dij(int s){ memset(vi…
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to deliver plenty of ice cold nutritiou…
[题解] 最短路.那么直接写dijkstra就好了. #include<cstdio> #include<algorithm> #include<cstring> #define LL long long #define rg register #define N 200010 using namespace std; int n,m,s,t,tot,last[N],dis[N],pos[N]; struct edge{ int to,pre,dis; }e[N<…
思路:裸SPFA过一遍(建议使用邻接链表存储),无向图,无向图,无向图,重要的事情要说三遍!!!蜜汁RE是什么鬼????第九个点数组开到20K,第十个点数组开到30K才AC.或许我代码写的有bug?(逃 CODE: #include<iostream> #include<queue> using namespace std; queue<int>q; struct Edge{ int pre,to,w; }edge[]; ]; ]; ]; int T, C, Ts, T…
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to deliver plenty of ice cold nutritiou…
题目链接 https://www.luogu.org/problemnew/show/P1339 最短路 解题思路 dijkstra直接过 注意: 双向边 memset ma数组要在读入之前 AC代码 #include<iostream> #include<cstring> using namespace std; int n,m,ts,te; ]; ]; ][]; int main(){ cin>>n>>m>>ts>>te; mem…
嗯... 题目链接:https://www.luogu.org/problem/P1339 这道题是水的不能在水的裸最短路问题...这里用的dijkstra 但是自己进了一个坑—— 因为有些城市之间可能还没有道路,自己只是将其初始化为0,而应该初始化为0x3f3f,从而表示两个城市之间没有道路... AC代码: #include<cstdio> #include<iostream> #include<algorithm> #include<cstring>…
AC代码 #include<bits/stdc++.h> using namespace std; const int MAXN=62000+10,INF=999999; struct Edge{ int u,v,w,next; }edge[MAXN]; int head[MAXN],n,m,s,t,dist[MAXN],cnt; bool vis[MAXN]; void addedge(int x,int y,int z){ edge[cnt].u=x; edge[cnt].v=y; edg…
原题:洛谷P2959 不得不说这道题的图有点吓人,但实际上很多都没有用 通过题上说的“三岔路口”(对于每一个节点有三条连接,其中一条连接父节点,另外两条连接子节点)和数据,可以那些乱七八糟的路和牧场看成是一棵二叉树,又因为 “对任意一个节点来说,只有一条从节点1开始的路径可以到达” ,所以可以把1作为根节点.从而将题目转化为求一棵以1为节点的二叉树的深度. 核心算法:DFS 注意: 1.根节点的深度在此题中应该为1(节点1的实际意义是一个要算入答案的一个牧场) 2.有n个节点,他们之间的连接数应…
Problem 洛谷P2845-Switching on the Lights 开关灯 Accept: 154    Submit: 499Time Limit: 1000 mSec    Memory Limit : 128MB Problem Description Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把多少个牛棚的灯打开. 有N*N个房间,组成了一张N*N的网格图,Bessie一开始位…
洛谷 1938  [USACO09NOV]找工就业Job Hunt 题目描述 Bessie is running out of money and is searching for jobs. Farmer John knows this and wants the cows to travel around so he has imposed a rule that his cows can only make D (1 <= D <= 1,000) dollars in a city be…
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players…