Created
June 10, 2015 23:54
-
-
Save balamark/0494cb0bb5b0129acedf to your computer and use it in GitHub Desktop.
think about it, how can we differentiate the case which takes zero digit with the valid case which take at least one digit?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
string s; | |
int n; | |
int dp[100][8]; | |
int solve(int p, int num){ | |
if(p==n){ | |
return dp[p][num] = (num==0); | |
} | |
if(dp[p][num]!=-1) return dp[p][num]; | |
int t = (num*10)+(s[p]-'0'); | |
//take digit at position p or not | |
int a = solve(p+1, t%8); | |
int b = solve(p+1, num); | |
return dp[p][num] = max(a,b); | |
} | |
int main(){ | |
cin>>s; | |
n = s.size(); | |
memset(dp, -1, sizeof dp); | |
if(solve(0,0)==0) cout<<"NO\n"; | |
else{ | |
for(int i=0;i<n;++i){ | |
if(dp[i][0]==1){ | |
return cout<<"YES\n", 0; | |
} | |
} | |
} | |
cout<<"NO\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment