Https://cn.vjudge.net/problem/Gym-101889E
1??????????????????????????????? 2
10000000000000000000000000000000
??????????????????????????????? 1 2
*
? 294?? 17
129404
Test instructions: Give a number (length <=1000), some digits unknown, to? Fill the number so that it can be divisible by the MoD (<=1000) and be the smallest (without the preamble 0).
Using the idea of digital DP, the former from small to large in order, Dp[pos][sta] mark the current state.
The usual digital DP mostly represents the number of scenarios, where only 01 indicates whether the state has occurred, so it achieves the effect of memory.
The number of the first satisfied condition found is the smallest one.
#include <bits/stdc++.h>#defineMAX 1005using namespaceStd;typedefLong Longll;intLen,mod;strings;intDp[max][max];intF;inlinevoidDfsintPosintStastringans) { if(f==1)return; if(pos==Len) { if(sta==0) {f=1; cout<<ans<<Endl; } return; } if(dp[pos][sta]==1)return; if(s[pos]=='?'){ for(intI=0; i<=9; i++){ if(pos==0&&i==0)Continue; if(f==1)return; DFS (POS+1, (sta*Ten+i)%mod,ans+ (Char) (i+'0')); if(f==1)return; } } Else{ if(f==1)return; DFS (POS+1, (sta*Ten+s[pos]-'0')%mod,ans+S[pos]); if(f==1)return; } Dp[pos][sta]=1;}intMainvoid) {cin>>s>>MOD; F=0; len=s.length (); DFS (0,0,""); if(f==0) cout<<"*"<<Endl; return 0;}
gym-101889e Enigma (Digital fill + memory)