HDU-3957 [Street Fighter] minimum governing set

Source: Internet
Author: User

The positive solution should be DLX. Unfortunately, some of them used DFS + pruning, and some others used Random Algorithms. Various orz ....

 

I used the DFS + pruning of a big bull and optimized it in binary format ,,,,

 

Code:

/* State compression + iterative deepening search * // * Minimum master set * // * AC code: 7437 Ms */# include <iostream> # include <cstdio> # include <memory. h> # include <algorithm> # define LL (A) (a <1) # define RR (A) (a <1 | 1) # define one (_ int64 (1) # define goal (_ int64) (one <(2 * n)-1) // target State: Using namespace STD; int N, Cas, Pn, M, K, depth ;__ int64 st [100] ;__ int64 rest [100] ;__ int64 state; void Init () {int I, J, K, U, V, ith; scanf ("% d", & N); State = 0; Pn = n <1; for (I = 0; I <PN; I ++) {st [I] = r Est [I] = 0; // indicates that if one of them is in another State, the St [I] cannot be processed | = (one <I ); st [I] | = (one <(I ^ 1) ;}for (I = 0; I <n; I ++) {scanf ("% d ", & M); If (M = 1) state | = (one <RR (I); // indicates that the for (j = 0; j <m; j ++) {u = (LL (I) | j; scanf ("% d", & K); {for (k = 0; k <K; k ++) {scanf ("% d", & V, & ith); V = (LL (V) | ith; st [u] | = (one <v) ;}}// pre-processing rest [pn-1] = sT [pn-1]; for (I = pn-2; i> = 0; I --) Rest [I] = sT [I] | rest [I + 1];} bool DFS (_ int64 state, int D, int P) {int I; If (D = depth) return state = goal; For (I = P; I <n; I ++) {If (state | rest [LL (I)])! = Goal) break; // pruning // If (state | st [LL (I)]) = State) continue; if (DFS (state | st [LL (I)], D + 1, I + 1) return true; If (state | rest [RR (I)])! = Goal) break; If (state | st [RR (I)]) = State) continue; If (DFS (state | st [RR (I)], d + 1, I + 1) return true;} return false;} void solve () {depth = 1; // printf ("@ % i64d \ n ", goal); While (depth <n) // iterations deepen {If (DFS (State,) break; depth ++;} printf ("case % d: % d \ n ", CAS ++, depth) ;}int main () {int t; CAS = 1; scanf (" % d ", & T ); while (t --) {Init (); solve ();} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.