[BZOJ] 3301: [USACO2011 Feb] Cow Line】的更多相关文章

康拓展开/逆展开 模板 #include<algorithm> #include<iostream> #include<cstdio> #define int long long using namespace std; inline int rd(){ int ret=0,f=1;char c; while(c=getchar(),!isdigit(c))f=c=='-'?-1:1; while(isdigit(c))ret=ret*10+c-'0',c=getcha…
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit][Status][Discuss] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer Joh…
http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开,然后拖到今天才来看看... sad.. 从不知道那里来的文档里边抄的: 康托展开就是一种特殊的哈希函数,它的使用范围是对于n个数的排列进行状态的压缩和存储.X=a[n]*(n-1)!+a[n-1]*(n-2)!+…+a[i]*(i-1)!+…+a[2]*1!+a[1]*0! 其中,a为整数,并且0<…
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 39[Submit][Status] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The co…
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=3301 康拓展开和逆展开的模板题. #include<iostream> #include<cstring> #include<cstdio> #define maxn 21 using namespace std; inline int read(){ register int x(0),f(1); register char c(getchar()); whi…
这道题和蔡大神出的今年STOI初中组的第二题几乎一模一样... 先跑一遍最短路 , 再把所有边反向 , 再跑一遍 , 所有点两次相加的最大值即为answer ----------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #in…
题目 1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 491  Solved: 362[Submit][Status] Description     农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前去X牛棚参加派对还是返回住所,她们都采用了用时最少的…
直接用STL的的deque就好了... ---------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<deque>   #define rep( i , n ) for( int i = 0 ; i &l…
水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ---------------------------------------------------------------------------------- #include<bits/stdc++.h>   #define rep(i, n) for(int i = 0; i < n; ++i) #define clr…
[题解] 很容易可以写出朴素DP方程f[i]=sigma f[j] (sum[i]>=sum[j],1<=j<=i).  于是我们用权值树状数组优化即可. #include<cstdio> #include<algorithm> #define N 200010 #define rg register #define LL long long #define Mod (1e9+9) using namespace std; int n,n2; LL t[N],f[…