2102: [Usaco2010 Dec]The Trough Game Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 117  Solved: 84[Submit][Status] Description Farmer John and Bessie are playing games again. This one has to do with troughs of water. Farmer John has hidden N (1 <= N…
http://www.lydsy.com/JudgeOnline/problem.php?id=2102 直接枚举所有情况......然后判断是否可行.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using…
跑两遍最短路就好了.. 话说这翻译2333 ---------------------------------------------------------------------- #include<cstdio> #include<queue> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i…
dp( l , r ) = sum( l , r ) - min( dp( l + 1 , r ) , dp( l , r - 1 ) ) 被卡空间....我们可以发现 l > r 是无意义的 , 所以可以省下一半的空间 -------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<a…
暴力枚举答案然后检验. #include<cstdio> int n,m,i,j,k,a[100],b[100],cnt,ans;char s[20]; int main(){ for(scanf("%d%d",&n,&m);i<m;i++)for(scanf("%s%d",s,&b[i]),j=0;j<n;j++)if(s[j]=='1')a[i]|=1<<j; for(i=0;i<(1<&l…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2101 题意: 共有n枚金币,第i枚金币的价值是w[i]. 把金币排成一条直线,Bessie和Bonny轮流取金币,看谁取到的钱最多. Bessie先取,每次只能取一枚金币,而且只能选择取直线两头的金币,不能取走中间的金币.当所有金币取完之后,游戏就结束了. Bessie和Bonny都是非常聪明的,她们会采用最好的办法让自己取到的金币最多. 请帮助Bessie计算一下,她能拿到多少钱? 题…
http://www.lydsy.com/JudgeOnline/problem.php?id=2101 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 539  Solved: 294[Submit][Status][Discuss] Description Bessie and Bonnie have found a treasure chest full of marvelous gold coins! Being cows, though,…
二分答案,然后dp判断是否合法 具体方法是设f[u]为u点到其子树中的最长链,每次把所有儿子的f值取出来排序,如果某两条能组合出大于mid的链就断掉f较大的一条 a是全局数组!!所以要先dfs完子树才能填a!! #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1000005; int n,m,h…
就是区间dp啦f[i][j]表示以i开头的长为j+1的一段的答案,转移是f[i][j]=s[i+l]-s[i-1]+min(f[i][j-1],f[i+1][j-1]),初始是f[i][1]=a[i] 于是可以把j维推掉 #include<iostream> #include<cstdio> using namespace std; const int N=5005; int n,a[N],s[N]; int main() { scanf("%d",&n…
洛谷数据好强啊,普通spfa开o2都过不了,要加双端队列优化 因为是双向边,所以dis(u,v)=dis(v,u),所以分别以pa1和pa2为起点spfa一遍,表示pb-->pa1-->pa2和pb-->pa2-->pa1,取个min即可 #include<iostream> #include<cstdio> #include<queue> using namespace std; const int N=200005,inf=2e9+7; in…