标签:des style blog java color os strong io
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2180 Accepted Submission(s): 787
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 #define inf 999999999 7 8 int a[22]; 9 char c[22]; 10 int n; 11 12 13 int dfs(int k,int step){ 14 15 if(k>=n){ 16 return a[k-1]?inf:step; 17 18 } 19 if(a[k-1]){ //若第K张牌前面一张牌为反面,那么需要翻第k张牌使得第k-1张牌正面朝上 20 a[k-1]=0; 21 a[k]=!a[k]; 22 a[k+1]=!a[k+1]; 23 step++; 24 } 25 return dfs(k+1,step); 26 } 27 28 main() 29 { 30 int i, j; 31 while(scanf("%s",c)!=EOF){ 32 n=strlen(c); 33 for(i=0;i<n;i++) a[i]=c[i]-‘0‘; 34 a[0]=!a[0];a[1]=!a[1]; //翻第一张牌 35 int num=inf; 36 37 num=min(num,dfs(1,1)); 38 for(i=0;i<n;i++) a[i]=c[i]-‘0‘; 39 num=min(num,dfs(1,0)); //不翻第一张牌 40 if(num==inf) printf("NO\n"); 41 else printf("%d\n",num); 42 } 43 }
HDU 2209 翻纸牌游戏(dfs),布布扣,bubuko.com
标签:des style blog java color os strong io
原文地址:http://www.cnblogs.com/qq1012662902/p/3868790.html