当前位置:网站首页>B. I hate 1111 (mnemonic search number theory

B. I hate 1111 (mnemonic search number theory

2022-06-13 07:18:00 lcxdz

Add link description
You can find the high order 1111 It can be done by 11 perhaps 111 form Then judge whether it can be 11 to be divisible by Or subtract 111 Regrouping
Memorize mp Whether storage can consist of

#include<bits/stdc++.h>
using namespace std;
map<int,bool>mp;
int dfs(int u){
    
    if(mp.count(u))return mp[u];
    int mx=0;
    for(int i=11;i<=u;i=i*10+1){
    
        mx=i;
    }
    for(int i=mx;i>=11;i=i/10){
    // It's a small judgment 
        // cout<<i<<"\n";
        if(dfs(u-i)){
    
            mp[u]=1;
            return mp[u];
        }
    }
    return mp[u];

}
int main(){
    
    int T;
    cin>>T;
    while(T--){
    
        mp[0]=1;// first 0 Is divisible 
        int x;
        cin>>x;
        if(dfs(x))cout<<"YES\n";
        else cout<<"NO\n";
        
    }


    return 0;
}
原网站

版权声明
本文为[lcxdz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130717471387.html