HDU4536+DFS
枚举支援的国家。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 DFS 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<iostream> 9 #include<queue> 10 //#include<map> 11 #include<math.h> 12 using namespace std; 13 typedef long long ll; 14 //typedef __int64 int64; 15 const int maxn = 105; 16 const int inf = 0x7fffffff; 17 const double pi=acos(-1.0); 18 const double eps = 1e-8; 19 const int maxm = 20; 20 struct node{ 21 int val,be; 22 }a[ maxm ]; 23 struct node2{ 24 int a,b,c; 25 }ord[ maxn ]; 26 int n,m,k; 27 int ans; 28 bool judge(){ 29 for( int i=0;i<n;i++ ) 30 if( a[ i ].val>5 ) 31 return false; 32 return true; 33 } 34 void dfs( int p ){ 35 ans = max( ans,p ); 36 if( p>=k ) return ; 37 38 int a1,a2,a3; 39 a1 = ord[ p ].a; 40 a2 = ord[ p ].b; 41 a3 = ord[ p ].c; 42 43 a[ a1 ].val-=2; 44 a[ a2 ].val+=2; 45 a[ a3 ].val+=2; 46 for( int i=0;i<n;i++ ){ 47 if( a[i].be==a[a2].be&&i!=a2 ) a[i].val++; 48 if( a[i].be==a[a3].be&&i!=a3 ) a[i].val++; 49 } 50 if( judge()==true ) dfs( p+1 ); 51 a[ a1 ].val+=2; 52 a[ a2 ].val-=2; 53 a[ a3 ].val-=2; 54 for( int i=0;i<n;i++ ){ 55 if( a[i].be==a[a2].be&&i!=a2 ) a[i].val--; 56 if( a[i].be==a[a3].be&&i!=a3 ) a[i].val--; 57 } 58 59 a[ a1 ].val+=2; 60 a[ a2 ].val-=2; 61 a[ a3 ].val+=2; 62 for( int i=0;i<n;i++ ){ 63 if( a[i].be==a[a1].be&&i!=a1 ) a[i].val++; 64 if( a[i].be==a[a3].be&&i!=a3 ) a[i].val++; 65 } 66 if( judge()==true ) dfs( p+1 ); 67 a[ a1 ].val-=2; 68 a[ a2 ].val+=2; 69 a[ a3 ].val-=2; 70 for( int i=0;i<n;i++ ){ 71 if( a[i].be==a[a1].be&&i!=a1 ) a[i].val--; 72 if( a[i].be==a[a3].be&&i!=a3 ) a[i].val--; 73 } 74 75 a[ a1 ].val+=2; 76 a[ a2 ].val+=2; 77 a[ a3 ].val-=2; 78 for( int i=0;i<n;i++ ){ 79 if( a[i].be==a[a2].be&&i!=a2 ) a[i].val++; 80 if( a[i].be==a[a1].be&&i!=a1 ) a[i].val++; 81 } 82 if( judge()==true ) dfs( p+1 ); 83 a[ a1 ].val-=2; 84 a[ a2 ].val-=2; 85 a[ a3 ].val+=2; 86 for( int i=0;i<n;i++ ){ 87 if( a[i].be==a[a2].be&&i!=a2 ) a[i].val--; 88 if( a[i].be==a[a1].be&&i!=a1 ) a[i].val--; 89 } 90 91 } 92 93 int main(){ 94 int ca; 95 scanf("%d",&ca); 96 for( int ii=1;ii<=ca;ii++ ){ 97 scanf("%d%d%d",&n,&m,&k); 98 for( int i=0;i<n;i++ ) 99 scanf("%d",&a[ i ].be); 100 for( int i=0;i<n;i++ ) 101 scanf("%d",&a[ i ].val); 102 for( int i=0;i<k;i++ ) 103 scanf("%d%d%d",&ord[ i ].a,&ord[ i ].b,&ord[ i ].c); 104 ans = 0; 105 dfs( 0 ); 106 printf("Case #%d: %d\n",ii,ans); 107 } 108 return 0; 109 } 110
keep moving...