• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

2021台北程序设计大赛跷跷板(背包)


Recommended Posts

image

image

问题转化为从甲,乙两组中分别取相同个数的东西的某一权值总和的最取次数

fa/b[j][v]表示前我个数,取j个,能否凑成体积五、六值就是0/1

注意控制合法状态,最后的枚举不要超过甲,乙的值域

#includebits/stdc .h

//#包含位/extc .h

使用命名空间标准

//使用命名空间_ _ gnu _ cxx

//使用命名空间_ _ gnu _ pbds

#定义IOS IOS : sync _ with _ stdio(false),cin.tie(0),cout。平局(0);

//#pragma GCC optimize(3,' Ofast ',' inline ')

#定义ll龙龙

#define li __int128_t

//#定义int long龙

const int N=1e5 5

const int M=1e 6 5;

const int mod=1e 9 7;

const ll LNF=0x 3 F3 F3 F3 F3 F3 f 3 f;

const double PI=acos(-1.0);

int a[105],b[105],cnta,cntb

bool fa[105][105][5055],FB[105][105][5055];

void solve() {

cnta=cntb=0;

memset(fa,0,sizeof fa);

memset(fb,0,sizeof FB);

int n,x;CIN n;

int suma=0,sumb=0,a=0,B=0;

for(int I=1;I=n;i ) {

宫颈癌前病变十世;

如果(x=2 ) b[ cntb ]=i,B=I;

sumb=x * I;

}

for(int I=1;I=n;i ) {

宫颈癌前病变十世;

如果(x=2 ) a[ cnta ]=i,A=I;

suma=x * I;

}

if(suma==sumb ) {

cout 0 ' \ n返回;

}

if(suma sumb) {

cout-1 ' \ n ';返回;

}

for(int I=0;I=cntaI)fa[0][0]=1;

for(int I=0;I=cntbI)FB[0][0]=1;//第二位是要控制合法状态,第一维不用

for(int I=1;i=cntai ) {

for(int j=1;j=cntaj ) {

for(int v=A;v=0;- v ) {//要继承

if(v=a fa[i - 1][j - 1][v - a])

fa[j][v]=fa[I-1][j-1][v-a];

if(fa[i - 1][j][v] 0)

fa[j][v]=fa[I-1][j][v];//要继承

}

}

}

for(int I=1;i=cntbi ) {

for(int j=1;j=cntbj ) {

for(int v=B;v=0;- v ) { //要继承

if(v=b fb[i - 1][j - 1][v - b])

FB[j][v]=FB[I-1][j-1][v-b];

if(fb[i - 1][j][v] 0)

FB[j][v]=FB[I-1][j][v];//要继承

}

}

}

int cha=suma-sumb;

for(int I=1;i=min(cnta,cntb);i ) {

int st=min(A,cha);//要在甲,乙值域内枚举

for(int j=ST;j=0;- j ) {

if(cha - j B)继续;//cha - j会特别大,就越界了

if(fa[cnta][j]0 FB[cntb][cha-j]0){

' cout i ' \ n

返回;

}

}

}

cout-1 ' \ n ';

}

int main() {

IOS

int t;CIN t;

while(t-)solve();

返回0;

}

Link to comment
Share on other sites