A DP began to write a question, So now no AC, so remember to engage in a search to steady your nerves ......
Links: https://ac.nowcoder.com/acm/problem/15035
Source: Cattle-off network
Hangzhou person silly man-made 62, while toot home here no such custom.
Compared to 62, there are more people hate him 38 digital, of course, that there are four
digital! So, ah, I do not want to toot not see the point included 38 digital or 4.
Every time a given interval [n, m], you can find all the unsavory figures it?
Enter a description:
Plural sets of input and output; Inputs are integers of n, m (0 <n≤m <1000000), If you encounter is an integer of 0, enter end.Output Description:
For each input The counted number of the output of all annoyingExample 1
Entry
1 100 0 0Export
20
Start thinking that this simple, either vector or direct health line and violent solution, then timeout
//记忆化搜索 送分了QAQ
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int num(ll n,ll m){
int dp[m+1]={0};
for(ll i=n;i<=m;i++){
ll q=i;
while(q!=0){
int x;
int y;
x=q%10;
q/=10;
y=q%10;
if(x==4||(x==8&&y==3)){
dp[i]++;
}
}
}
int sum=0;
for(int k=n;k<=m;k++){
if(dp[k]!=0){
sum++;
}
}
return sum;
}
int main(){
ll n,m;
while(true){
cin>>n>>m;
if(n==0&&m==0)
break;
cout<<num(n,m)<<endl;
}
return 0;
}
Of course timeout, as we do a lot of repetitive calculations, think of it is the memory of the search ah, all within a one-time solution to calculate, and then each solution based on the input range of the output on the line, quickly AC:
//记忆化搜索 送分了2
//送分个屁
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int a[1000000];
//一次全部计算完毕
int num(){
int ans=0;
for(int i=0;i<=1000000;i++){
int q=i;
while(q!=0){
int x;
int y;
x=q%10;
q/=10;
y=q%10;
if(x==4||(x==8&&y==3)){
a[i]++;
}
}
}
}
int sum(int n,int m){
int ans=0;
for(int i=n;i<=m;i++){
if(a[i]!=0){
ans++;
}
}
return ans;
}
int main(){
ll n,m;
num();
while(true){
cin>>n>>m;
if(n==0&&m==0)
break;
cout<<sum(n,m)<<endl;
}
return 0;
}