传送门 解题思路 组合数学.首先肯定是要先枚举位数,假如枚举到第\(i\)位.我们可以把第一位固定,然后那么后面的随意放\(1\),个数就为\(C_{i-1}^{k-1}\).然后每次枚举时如果方案\(>n\)就说明位数为\(i\),否则就让\(n-C_{i-1}^{k-1}\),然后继续枚举下去.这样的话我们就确定了第一位,后面的位其实和数位\(dp\)里试填法的思路差不多,就是看\(n\)是否大于当前位为\(0\)时后面的方案数,如果大就把这一位设为\(1\),然后减掉方案.算组合数有一个小…
P3048 [USACO12FEB]牛的IDCow IDs 12通过 67提交 题目提供者lin_toto 标签USACO2012 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 谁能解释一下这个样例啊.... 题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitiou…
题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitious, and only labels cows with binary numbers that have exactly K "1" bits (1 <= K <= 10). The leading bit of each la…
题目: FJ给他的奶牛用二进制进行编号,每个编号恰好包含K 个"1" (1 <= K <= 10),且必须是1开头.FJ按升序编号,第一个编号是由K个"1"组成. 请问第N(1 <= N <= 10^7)个编号是什么. 不同寻常的暴力: 样例是升序的第7个,我把1--7都列出来. 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 0 发现的规律是,每次将二进制串的从右往左数的第…
题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitious, and only labels cows with binary numbers that have exactly K "1" bits (1 <= K <= 10). The leading bit of each la…
P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 86分求救 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget…
[USACO12FEB]牛券Cow Coupons(堆,贪心) 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). Cow i costs P_i money (1 <= P_i <= 10^9), b…
P3045 [USACO12FEB]牛券Cow Coupons 贪心题.先选中 \(c_i\) 最小的 \(k\) 头牛,如果这样就超过 \(m\) ,直接退出,输出答案.否则考虑把后面的牛依次加入,替换前面用过券的牛.这里贪心得选择省钱最少的牛替换掉(这样影响最小,最有可能多买几头).加入牛的顺序按照 \(p\) 从小到大,因为如果换不掉就只能话 \(p\) 的钱去买 #include<bits/stdc++.h> using namespace std; #define int long…
传送门 解题思路 树形dp,看到数据范围应该能想到是O(nk)级别的算法,进而就可以设出dp状态,dp[x][j]表示以x为根的子树,距离它为i的点的总和,第一遍dp首先自底向上,dp出每个节点的子树中到他距离为j的,转移方程dp[x][j]=dp[u][j-1] ,第二遍dp自顶向下,dp出每个节点父亲那头的距离为j的,转移方程dp[u][j]+=dp[x][j-1]-dp[u][j-2] 代码 //dp[x][j] 以i为根的子树,距离为j的牛的和 //dp[x][j]+=dp[u][j-1…
题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into account, he wants to plant enough grass in each of his fields not only for the cows situated initially in that field, but also for cows visiting from nearby…