线段树.. --------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define rep( i , n ) for( int i = 0 ; i < n ; ++i ) #define clr(…
在线段树上记录长度.区间01翻转标记.当前1个数.传递tag的时候用长度-1个数即可 #include<iostream> #include<cstdio> using namespace std; const int N=100005; int n,m; struct qwe { int l,r,len,v,tg; }t[N<<2]; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0…
状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) = Σ dp( i , S - { i } ) ( i ∈ S , abs( h[ i ] - h[ x ] ) > k ) ------------------------------------------------------------------------------------------- #include<cstdio> #includ…
无限背包dp.. 因为题目中说至少到 H 磅 , 我就直接把 H * 2 了.. -------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define rep( i , n ) for( int i = 0 ; i…
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 Solved: 218 [Submit][Status] Description The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable…
Description Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs conveniently numbered 1..N (1 <= N <= 1,000) to accomplish (like milking the cows, cleaning the barn, mending the fences, and so…
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 920 Solved: 569[Submit][Status][Discuss] Description Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs conveniently numbered 1..N (1 <= N <= 1,0…
好像是完全背包吧分不清了-- 好像是把数组二维压一维的时候,01背包倒序,完全背包正序 ```cpp include include using namespace std; const int N=105,H=55005; int n,h,p[N],c[N],f[H]; int main() { scanf("%d%d",&n,&h); for(int i=1;i<=n;i++) scanf("%d%d",&p[i],&c[i…
设f[i][j]为奶牛选取状态为i,最后一头选的为j,转移直接f[k][(1<<(k-1)|i]+=f[j][i] #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,m,p[20],a[20]; long long f[20][1<<16],ans; int main() { scanf("%d%d",&…
开始读错题了,然后发现一眼切~ Code: #include <cstdio> #include <algorithm> #define ll long long #define setIO(s) freopen(s".in","r",stdin) using namespace std; int s[20]; ll dp[1<<18][17],fac[20]; int main() { // setIO("input&…
1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 506 Solved: 306[Submit][Status] Description Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs convenien…