dls说这是道无聊的题
构造一个有向带权图,使得恰有K个0-1最小割。
0-1最小割是将图分成S和T两个集合,0属于S, 1属于T,权值为从S到T的边的边权和。
K<=1000,要求点数<=20假设有个x的方案,构造2x和x+1。
构造2x十分简单,只要加一个空的点即可。
构造x+1的方案,只要加一个点p,然后向2到p-1全都连上边即可。
这样0-1的最小割始终为0。如果p被选到了S集,那么得把2到p-1全都选过来,否则无所谓,方案总数为x+1。
这样..最小割就都是0了
// BEGIN CUT HERE
#include<conio.h>
#include<sstream>
// END CUT HERE
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#define pb push_back
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
int ncnt;
vector<int> ans;
inline void Solve(int n){
if (n==1) return;
if (~n&1){
Solve(n>>1);
++ncnt;
}else{
Solve(n-1);
++ncnt;
for (int i=2;i<ncnt;i++)
ans.pb(ncnt),ans.pb(i),ans.pb(1);
}
}
class MinimumCutsAgain{
public:
vector <int> construct(int n){
ans.clear();
ans.pb(0); ncnt=1;
Solve(n);
ans[0]=ncnt+1;
return ans;
}
// BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const vector <int> &Expected, const vector <int> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
void test_case_0() { int Arg0 = 1; int Arr1[] = {2, 0, 1, 6 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(0, Arg1, construct(Arg0)); }
void test_case_1() { int Arg0 = 2; int Arr1[] = {3, 0, 2, 1, 0, 1, 1, 2, 1, 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(1, Arg1, construct(Arg0)); }
void test_case_2() { int Arg0 = 4; int Arr1[] = {4, 0, 2, 4, 2, 1, 4, 0, 3, 2, 3, 1, 2 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(2, Arg1, construct(Arg0)); }
void test_case_3() { int Arg0 = 6; int Arr1[] = {6, 0, 1, 1, 0, 5, 2, 1, 0, 4, 1, 2, 1, 1, 3, 2, 1, 4, 1, 2, 5, 1, 3, 4, 2 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(3, Arg1, construct(Arg0)); }
void test_case_4() { int Arg0 = 752; int Arr1[] = {20, 0, 16, 1, 1, 5, 2, 2, 11, 2, 3, 5, 2, 5, 2, 1, 5, 3, 1, 5, 11, 1, 7, 4, 2, 7, 18, 1, 9, 3, 2, 9, 17, 1, 11, 10, 2, 13, 1, 1, 13, 5, 2, 13, 15, 1, 14, 16, 2, 14, 17, 1, 16, 6, 2, 16, 13, 1, 16, 17, 1, 17, 12, 1, 18, 3, 2, 18, 6, 1, 19, 15, 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(4, Arg1, construct(Arg0)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main(){
MinimumCutsAgain ___test;
___test.run_test(-1);
getch() ;
return 0;
}
// END CUT HERE