gym-101889e Enigma (Digital fill + memory)

Source: Internet
Author: User

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)

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.