直接dfs即可...emmm好水,好了,学树状数组线段树去了...ggg
#include <bits/stdc++.h> using namespace std; const int N=100; string s; int vis[N],ans; void dfs(int u,int op) { //cout<<s.size()<<endl; //cout<<u<<' '<<op<<endl; if(op==1) { if(vis[s[u]-'0']) return; vis[s[u]-'0']=1; if(u==s.size()-1) { ans++; vis[s[u]-'0']=0; return; } dfs(u+1,1); dfs(u+1,2); vis[s[u]-'0']=0; } else { if(u+1>=s.size()) return; if(vis[(s[u]-'0')*10+(s[u+1]-'0')]||(s[u]-'0')==0) return; vis[(s[u]-'0')*10+(s[u+1]-'0')]=1; if(u==s.size()-2) { ans++; vis[(s[u]-'0')*10+(s[u+1]-'0')]=0; return; } dfs(u+2,1); dfs(u+2,2); vis[(s[u]-'0')*10+(s[u+1]-'0')]=0; } } int main() { while(cin>>s) { ans=0; memset(vis,0,sizeof vis); dfs(0,1); dfs(0,2); printf("%d\n",ans); } return 0; }