题面
题意
给你一个数,判断它能否由11,111,1111,11111 …组成
题解(打表)
我们通过dfs打表发现,大于10000的数都是可以由题中所给条件组成的,所以我们只需要存放10000的数进行判断即可。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const int maxn=10000;
int t,n;
int arr[]={11,111,1111};
map<int,int> mp;
void dfs(){
queue<int> q;
q.push(0);
while (q.size()){
int x=q.front();
q.pop();
for(int i=0;i<3;i++){
if(mp[x+arr[i]]==0&&x+arr[i]<=maxn){
mp[x+arr[i]]=1;
q.push(x+arr[i]);
}
}
}
}
int main(){
dfs();
cin>>t;
while(t--){
cin>>n;
if(n<=10000){
if(mp[n]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
}
return 0;
}