P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top…
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a proble…
题目传送门 摩天大楼里的奶牛 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, th…
题目描述 给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组.(n<=18) 输入格式: Line 1: N and W separated by a space. Lines 2..1+N: Line i+1 contains the integer C_i, giving the weight of one of the cows. 输出格式: Line 1: A single integer, R, indicating the minimum number…
这个状压dp其实很明显,n < 18写在前面了当然是状压.状态其实也很好想,但是有点问题,就是如何判断空间是否够大. 再单开一个g数组,存剩余空间就行了. 题干: 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after…
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a proble…
洛谷题目链接:[USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top…
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a proble…
题目链接 状压\(dp\) 根据套路,先设\(f[sta]\)为状态为\(sta\)时所用的最小分组数. 可以发现,这个状态不好转移,无法判断是否可以装下新的一个物品.于是再设一个状态\(g[sta]\)表示状态为\(sta\)时 每组剩下的体积的最大值 的最大值,当枚举状态为\(sta\),枚举到第\(i\)个时,可以得到\(g\)的转移: \[ g[v]=max(g[v],g[sta]-w[i]) \] 其中,\(v​\)为转移后的状态. 然后每次就可以根据\(g\)来转移\(f\)了. #…
传送门 输出被阉割了. 只输出最少分的组数即可. f 数组为结构体 f[S].cnt 表示集合 S 最少的分组数 f[S].v 表示集合 S 最少分组数下当前组所用的最少容量 f[S] = min(f[S], f[S - i] + a[i]) (i ∈ S) 运算重载一下即可. ——代码 #include <cstdio> #include <iostream> int n, m, w; ]; struct qwq { int cnt, v; qwq(, ) : cnt(cnt),…
不打算把题目放着,给个空间传送门,读者们自己去看,传送门(点我)    . 这题是自己做的第一道状态压缩的动态规划. 思路: 在这题中,我们设f[i]为i在二进制下表示的那些牛所用的最小电梯数. 设g[i]为i在二进制下表示的那些牛使用的电梯中剩下的最大容量. 所以很明显的,我们只要枚举每一只牛就可以了. 如果当前状态下,最大容量能装进某只牛,则装进去,并且用两个变量保存装进去后的f值与g值,否则再使用一个新的电梯,并且用变量保存用新电梯后的f与g值. 在每次的枚举,我们还要将当前保存的f值与g…
状压DP: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a = (b); a <= (c); ++ a) #define nR(a,b,c) for(register int a = (b); a >= (c); -- a)…
(已经一句话了) 第一反应:暴力 第二反应:朴素算法过不去 第三反应:没法折半暴搜(没法统计答案) 所以,歪歪了一个类似贪心刷表的方法,过了这道题. 首先,如果爆搜的话会有几个状态: 当前牛 当前几个箱子 当前的牛数量 而且它的复杂度是阶乘级别. 发现这道题目有显然单调性(答案处在分界线,-1不合法,+1不是最优)所以歪歪了一个类似二分check的dfs方法. 那么状态就得改变了.传入的还是牛的编号,但是,在dfs内部,枚举的是当前的牛放在哪个箱子里.如果能搜到最后一步,就返回. 于是乎,这样d…
迭代加深搜索基础 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had…
题意 给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组.(n<=18) 题解 一看以为是弱智题.(可能真的是,我太菜了) 然后跟walthou夸下海口:这么简单我做出来给你讲. 结果就被打脸了(对waithou说:我不会,自己看题解吧) 然后我就看了题解.. 设dp[i][j]为当前选i组已经选的情况为j的第i组的最小重量. 然后转移时,一个一个奶牛转移. 具体就是对于枚举的状态,如果dp[i][j]有不为INF,就枚举一个不属于j的x. 方程是 dp[i][j…
一道状压题,但今天闲来无事又用遗传乱搞了一下. 设了一个DNA数组,DNA[i]记录第i个物品放在哪个组里.适应度是n-这个生物的组数+1. 交配选用的是轮盘赌和单亲繁殖——0.3的几率单点变异.(事实上有性生殖我似乎写不出来……代码量略大) 种群大小开到了400,在vijos上繁殖了2050代,下数据自己测也是对的. 然而只有84分 这究竟是为什么啊    下数据自己测是没错的啊……………… 疯了 代码和数据先放到这里,以后再改吧 #include<cstdio> #include<c…
参见ZHT467的题解. f[i]表示在i这个集合下的最少分组数和当前组最少的容量. 从1到(1<<n)-1枚举i,对于每个i枚举它的子奶牛,然后重载运算符计算. 代码如下 #include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<cmath> #include<algorithm> using namespace std…
题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所有奶 牛都是自恋狂,每头奶牛总是喜欢自己的.奶牛之间的“喜欢”是可以传递的——如果A喜 欢B,B喜欢C,那么A也喜欢C.牛栏里共有N 头奶牛,给定一些奶牛之间的爱慕关系,请你 算出有多少头奶牛可以当明星. 输入输出格式 输入格式:  第一行:两个用空格分开的整数:N和M  第二行到第M + 1行:每行两个用空格分开的整数:A和B,表示A喜欢B 输出格式:  第一行:单独一个整数,表示明星奶牛的数量 输入输出样…
P2698 [USACO12MAR]花盆Flowerpot 题目描述 Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical he…
题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle of the field. His cows, always up to no good, decide to play a prank of Farmer John: they deposit N bales of hay (1 <= N <= 50,000) at various locati…
题目描述 After several months of rehearsal, the cows are just about ready to put on their annual dance performance; this year they are performing the famous bovine ballet "Cowpelia". The only aspect of the show that remains to be determined is the s…
https://www.luogu.org/problemnew/show/P1849 题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle of the field. His cows, always up to no good, decide to play a prank of Farmer John: they deposit N bales…
SG函数的应用 看到这题就想到了SG函数 那么可以考虑最终情况:一个数是x,另一个是0,那么先手必败(因为上一个人已经得到0了,其实游戏已经结束了) 剩下的情况:一个数n, 一个数m,假设n>m 那么根据题意,SG(n,m)=mex{SG(n - m, m), SG(n - 2m, m), ......, SG(m, n%m)(此处交换了顺序,因为 m>n%m )} 考虑里面的SG怎么求. 可以发现,SG(n-m, m)=mex{SG(n-2m, m), SG(n-3m, m)........…
P3670 [USACO17OPEN]Bovine Genomics S奶牛基因组(银) 题目描述 Farmer John owns NN cows with spots and NN cows without spots. Having just completed a course in bovine genetics, he is convinced that the spots on his cows are caused by mutations in the bovine genom…
题目描述 欧几里德的两个后代Stan和Ollie正在玩一种数字游戏,这个游戏是他们的祖先欧几里德发明的.给定两个正整数M和N,从Stan开始,从其中较大的一个数,减去较小的数的正整数倍,当然,得到的数不能小于0.然后是Ollie,对刚才得到的数,和M,N中较小的那个数,再进行同样的操作……直到一个人得到了0,他就取得了胜利.下面是他们用(25,7)两个数游戏的过程: Start:25 7 Stan:11 7 Ollie:4 7 Stan:4 3 Ollie:1 3 Stan:1 0 Stan赢得…
题面 看起来非常简单,但是细节多的一批的状压DP入门题. 我设 \(f_i\) 为 \(i\) 状态时最小分组数, \(g_i\) 为 \(i\) 状态时最后一组剩余空间. 对于每一个 \(i\) ,枚举每一个 \(1\le j\le n\) 且 \(j\) 不在 \(i\) 内, 即 \(i \& (1<<(j-1))=0\) .然后分类讨论: \(j\) 可以放在最后一组中, \(f_{i | (1<< (j-1))}=\operatorname{min}\{f_{i…
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afternoon treats. The co…
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afternoon treats. The co…
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afternoon treats. The co…
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afternoon treats. The co…