Hdu 2209 Turn Solitaire Game

Source: Internet
Author: User

is in accordance with the greedy ideas, divided into the first card to consider, the next time each search to see the front of a 0 or 1, 1 words on the turn, and finally look at the status of the last card.

#include <stdio.h>#include <algorithm>#include <string.h>using namespace STD;Const intinf=1<< -;intans,len,a[ -];Chars[ -];intDfsintCntintNow) {if(Now==len) {if(a[now-1]==0)returnCntElse returnInf }Else if(a[now-1]) {a[now-1]=!a[now-1];        A[now]=!a[now]; a[now+1]=!a[now+1];    cnt++; } DFS (cnt,now+1);}intMain () {intI while(~scanf('%s ', s)) {ans=inf; len=strlen(s); for(i=0; i<len; i++) a[i]=s[i]-' 0 '; a[0]=!a[0]; a[1]=!a[1]; Ans=min (Ans,dfs (1,1)); for(i=0; i<len; i++) a[i]=s[i]-' 0 '; Ans=min (Ans,dfs (0,1));if(Ans==inf)printf("no\n");Else printf("%d\n", ans); }return 0;}

Hdu 2209 Turn Solitaire Game

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.