居然要用高精度! 懒得operator了,转移是裸的完全背包 #include<iostream> #include<cstdio> using namespace std; int n,k,f[1005][45]; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') { if(p=='-') f=-1; p=getchar(); } while(p>='0'&&p<…
http://www.lydsy.com/JudgeOnline/problem.php?id=1655 背包就没什么好说的了,裸的完全背包.. 但是我一开始交开了ull都wa了T_T.. 精度太大... .. 打高精度吧.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algori…
Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1…
Description 约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,-,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢? Input A single line with two space-separated integers: N and K. 仅一行,输入N,K. Output A single line with a single integer that is the number of unique ways FJ…
1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that ton…
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm>   using namespace std;   const int maxn = 5009;   struct edge { int…
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[Submit][Status][Discuss] Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is grazing in one of N (1 <= N <…
1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 891  Solved: 590[Submit][Status][Discuss] Description FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:).在赛场上,奶牛们按1..N依次编号.每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名. 整个比…
对于第 i 头牛 , 假如排名比它高和低的数位 n - 1 , 那么他的 rank 便可以确定 . floyd --------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep…
直接从每个奶牛所在的farm dfs , 然后算一下.. ---------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<vector>   #define rep( i…
Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance. Only cows can perform the…
http://www.lydsy.com/JudgeOnline/problem.php?id=1720 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 177  Solved: 90[Submit][Status][Discuss] Description Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corr…
几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=10005; int n,m,h[N],cnt,ans,tmp,dfn[N],low[N],s[N],top; bool v[N]; struct qwe { int ne,to; }e[N*10]; int read() { i…
Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is grazing in one of N (1 <= N <= 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 <= M <= 10,000) one-way paths (no p…
Description FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:).在赛场上,奶牛们按1..N依次编号.每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名. 整个比赛被分成了若干轮,每一轮是两头指定编号的奶牛的对决.如果编号为A的奶牛的编程能力强于编号为B的奶牛(1 <= A <= N; 1 <= B <= N; A != B) ,那么她们的对决中,编号为A的奶牛总是能胜出. FJ想知道奶…
从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可 #include<iostream> #include<cstdio> using namespace std; const int K=105,N=1005; int k,n,m,p[K],h[N],cnt,c[N],v[N],ti,ans; struct qwe { int ne,to; }e[N*10]; int read() { int r=0,f=1;…
Description 给出一个无向图,求将他构造成双连通图所需加的最少边数. Sol Tarjan求割边+缩点. 求出割边,然后缩点. 将双连通分量缩成一个点,然后重建图,建出来的就是一棵树,因为每一条边都是桥. 然后每次合并这棵树上的叶节点两点距离LCA最远的点,这样就会形成一个环,是双连通的,然后进行(ans+1)/2次操作就可以了. 其实就是(叶节点个数+1)/2 Code #include<cstdio> #include<vector> #include<iost…
Description The pasture contains a small, contiguous grove of trees that has no 'holes' in the middle of the it. Bessie wonders: how far is it to walk around that grove and get back to my starting position? She's just sure there is a way to do it by…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1656 题意: 给你一个n*m的地图,'.'表示空地,'X'表示树林,'*'表示起点. 所有'X'为一个连通块. 对于每一个点,你可以向周围八个方向走,均算作一步. 让你找出一条路径,能够将所有'X'包围. 问你路径最短为多少. 题解: bfs + 射线法. 找出最上面(x坐标最小)的一个'X',并向上方作一条射线,标记为'#'. 从起点开始bfs,并且不能穿过射线(即'#'不能到达).…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1612 题意: 有n头牛比赛. 告诉你m组(a,b),表示牛a成绩比牛b高. 保证排名没有并列. 问你有多少只牛的排名已经确定. 题解: 对于一头牛,它的排名确定的条件是:它前面的牛数量 + 它后面的牛数量 = n-1 所以对于(a,b),连一条有向边a->b. 然后做floyd传递闭包. 枚举每一头牛,统计与它连通的牛的个数sum. 如果sum = n-1,则ans++. AC Code…
floyd传递关系,一个牛能确定排名的条件是能和所有牛确定关系 #include<iostream> #include<cstdio> using namespace std; const int N=105; int n,m,a[N][N],ans; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&…
首先来分析一下,这是一张无向图,要求没有两条路联通的点对个数 有两条路连通,无向图,也就是说,问题转化为不在一个点双连通分量里的点对个数 tarjan即可,和求scc还不太一样-- #include<iostream> #include<cstdio> using namespace std; const int N=5005; int n,m,h[N],cnt=1,x,y,dfn[N],low[N],tmp,s[N],top,bl[N],col,d[N],ans; bool v[…
题意:给出整数n和k,n代表拥有的钱数量,k代表有k种工具,其价钱分别为1~k.求n元能有多少种购买的方案. 思路:k最大有100,数量过大,要用大数.其他的基本和完全背包一样. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; , N=; ], n, k; struct bign { //请先设置常数N作为缓冲…
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description 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 afterno…
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1132  Solved: 590[Submit][Status][Discuss] Description     为了从F(1≤F≤5000)个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了被迫走某一条路,所以她们想建一些新路,使每一对草场之间都会至少有两条相互分离的…
1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 645  Solved: 433[Submit][Status] Description FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:).在赛场上,奶牛们按1..N依次编号.每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就是说,奶牛们的编程能力有明确的排名. 整个比赛被分成了若干轮,…
Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5655   Accepted: 2125 Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are sell…
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 432  Solved: 270[Submit][Status] Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is grazing in one of N (1 <= N <= 1,000)…
[bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿,现在给你一个k,表示你最多可以删去k类数.数列中相同的数字被称为一类数.设该数列中满足所有的数字相等的连续子序列被叫做完美序列,你的任务就是通过删数使得该数列中的最长完美序列尽量长. Input Line 1: Two space-separated integers: N and K. Lines 2..…
POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自是1美元,2美元-K美元且能够无限使用,问你用上面K种硬币构成n美元的话有多少种方法? 分析: 本题是一道明显的全然背包问题, 只是本题还能够换一种方法来看: 整数n由前K个自然数构造, 一共同拥有多少种方法? (尽管本题要用到高精度加法, 可是非常easy, 不要被吓到哦) 首先是DP部分: 令dp[i][…