HDU 4536 Dfs

Source: Internet
Author: User

Test instructions: Xcom-enemy unknown is a very fun and classic strategy game.
In the game, due to unknown enemy-alien invasion, you unite the world's major countries for resistance. As the game progresses, there will be a lot of alien attacks. Every time you attack aliens will choose 3 countries to attack, as the commander of the Alliance, you have to arrange a limited coalition to support one of the countries, Resist the aliens attacking the country. After the battle victory, the supported country's panic value will be 2 points (the panic value is reduced to 1), while the other two non-supported countries panic value will be 2 points, and the two countries on the same continent of other countries panic value will be + 1 points. When a country's panic is worth more than 5, The country would lose faith in the alliance and withdraw from the alliance. Now give you the place where the aliens will attack and ask you how many times you can resist an alien attack without losing trust in any country.

Link: Point Me

1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; A #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); - Const intmaxn=1005; the intn,m,tt,k; - intMax_num; - intid[maxn],a[maxn][3],NEV[MAXN]; - voidDfsintnum) + { -     if(max_num>=k)return; +     if(num>=k) A     { atmax_num=K; -         return; -     } -      for(intI=0;i<3; i++)//enumerate the supported countries -     { -         intk1=Nev[a[num][i]]; in         intk2=nev[a[num][(i+1)%3]]; -         intk3=nev[a[num][(i+2)%3]];//back up the panic of three attacking countries. tonev[a[num][i]]-=2; +         if(nev[a[num][i]]<=0) nev[a[num][i]]=1; -nev[a[num][(i+1)%3]]+=2; thenev[a[num][(i+2)%3]]+=2; *          for(intj=0; j<n;j++) $         {Panax Notoginseng             if(Id[j]==id[a[num][(i+1)%3]]&&j!=a[num][(i+1)%3]) nev[j]+=1; -             if(Id[j]==id[a[num][(i+2)%3]]&&j!=a[num][(i+2)%3]) nev[j]+=1; the         } +         BOOLflag=1; A          for(intj=0; j<n;j++) the         { +             if(nev[j]>=6) -             { $max_num=Max (max_num,num); $flag=0; -                  Break; -             } the         } -         if(flag) DFS (num+1);Wuyi  the          for(intj=0; j<n;j++) -         { Wu             if(Id[j]==id[a[num][(i+1)%3]]&&j!=a[num][(i+1)%3]) nev[j]-=1; -             if(Id[j]==id[a[num][(i+2)%3]]&&j!=a[num][(i+2)%3]) nev[j]-=1; About         } $nev[a[num][i]]=K1; -nev[a[num][(i+1)%3]]=K2; -nev[a[num][(i+2)%3]]=K3;//Restore the panic values of three attacking countries -     } A } + intMain () the { -     inti,j; $ #ifndef Online_judge theFreopen ("1.in","R", stdin); the     #endif thescanf"%d",&TT); the     intKase=0; -      while(tt--) in     { thekase++; thescanf"%d%d%d",&n,&m,&k); About          for(i=0; i<n;i++) the         { thescanf"%d",&id[i]); the         } +          for(i=0; i<n;i++) -         { thescanf"%d",&nev[i]);Bayi         } the          for(i=0; i<k;i++) thescanf"%d%d%d", &a[i][0],&a[i][1],&a[i][2]); -max_num=0; -printf"Case #%d:", Kase); theDfs0); theprintf"%d\n", max_num); the     } the}

HDU 4536 Dfs

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.