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…
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 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…