這樣一道傻題我調了這麼久
三個任務建圖是這樣的,由於太簡單就不xjb解釋了,乙個點拆位入點和出點
graph lr
s==w=1,c=1==>入點1
入點1 --w=1,c=點權1--> 出點1
入點2 --w=1,c=點權2--> 出點2
入點3 --w=1,c=點權2--> 出點3
出點1 --w=1,c=0--> 入點2
出點1 --w=1,c=0--> 入點3
出點2 ==w=1==>t
出點3 ==w=1==>t
graph lr
s==w=1,c=1==>入點1
入點1 --w=2,c=點權1--> 出點1
入點2 --w=2,c=點權2--> 出點2
入點3 --w=2,c=點權2--> 出點3
出點1 --w=1,c=0--> 入點2
出點1 --w=1,c=0--> 入點3
出點2 ==w=inf==>t
出點3 ==w=inf==>t
graph lr
s==w=1,c=1==>入點1
入點1 --w=inf,c=點權1--> 出點1
入點2 --w=inf,c=點權2--> 出點2
入點3 --w=inf,c=點權2--> 出點3
出點1 --w=inf,c=0--> 入點2
出點1 --w=inf,c=0--> 入點3
出點2 ==w=inf==>t
出點3 ==w=inf==>t
一次加邊即可,不過由於是費用流所以貌似要重置殘餘網路
注意陣列大小和邊界!好坑。
//@winlere
#include#include#include#include#includeusing namespace std; typedef long long ll;
inline int qr()
const int maxn=1e3+5;
struct e
e(const int&a,const int&b,const int&c,const int&d)
inline void print()
}e[maxn*maxn<<3];
int head[maxn*15];
int cnt=1;
int data[55][55];
int id[55][55];
int nodecnt;
int s,t;
int n,m;
int ts,tt;
inline void add(const int&fr,const int&to,const int&w,const int&c,const int&f=1)
queue < int > q;
const int inf=0x3f3f3f3f;
int in[maxn*15];
int fl[maxn*15];
int last[maxn*15];
int d[maxn*15];
inline int mincost()}}
//cout<<"fl[t]="
ret+=d[t]*fl[t];
for(register int t=t;t!=s;t=e[last[t]^1].to)
e[last[t]].w-=fl[t],e[last[t]^1].w+=fl[t];
}return ret;
}inline void reset()
}int main()
s=++nodecnt;
t=++nodecnt;
for(register int t=1;t<=n;++t)
}int ans1,ans2,ans3;
ts=++nodecnt;
add(s,ts,m,0);
for(register int t=1;t<=m;++t)
//cout
ans1=mincost();
reset();
//cout/return 0;
for(register int t=1;t<=n;++t)
for(register int i=1;i<=m+t-1;++i)
add(id[t][i],id[t][i]+1,inf,data[t][i]);
ans2=mincost();
reset();
for(register int t=1;t<=n;++t)
}ans3=mincost();
printf("%d\n%d\n%d\n",-ans1,-ans2,-ans3);
return 0;
}
題解 數字遊戲
the game is on.sherlock holmes 問題描述 遊戲是這樣的 在你面前有一圈整數 一共n個 你要按順序將其分為m個部分,各部分內的數字相加,相加所得的m個結果對10取模後再相乘,最終得到乙個數k。遊戲的要求是使你所得的k最大或者最小。例如,對於下面這圈數字 n 4,m 2 最...
HDU X mod f x 題解(數字dp)
在1 l r 1e9內,找出有多少個數mod 自己每一位數和 為0 顯然是數字dp,但是比較巧妙的是要,列舉mod,還有這個卡空間,不能直接return dp pos mod digsum digmod limit 就是不要你乘以兩倍。可以令 dp pos mod digsum digmod 都為l...
luogu P4013 數字梯形問題
三倍經驗,三個條件,分別對應了常見的3種模型,第一種是限制每個點只能一次且無交點,我們可以把這個點拆成乙個出點乙個入點,capacity為1,這樣就限制了只選擇一次,第二種是可以有交點,但不能有交邊,那我們就不需要拆點,限制每條capacity都為1就可以了,第三種直接連,沒有限制 includeu...