标签:sans show input other 安全 答案 reg select family
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[11][2],a[11];
inline int read()
{
	register int ans=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch==‘-‘) f=-1;ch=getchar();}
	while(isdigit(ch)) {ans=ans*10+ch-‘0‘;ch=getchar();}
	return ans*f;
}
int dfs(int wi,bool pre,bool lim)
{
	int ans=0;
	if(wi<1) return 1;
	if(!lim&&dp[wi][pre]!=-1)
	  return dp[wi][pre];
	int o=lim? a[wi]:9;
	for(int i=0;i<=o;i++)
	  if(i!=4&&(!pre||i!=2))
	    ans+=dfs(wi-1,i==6,lim&&i==a[wi]);
	if(!lim) dp[wi][pre]=ans;
	return ans;
}
int sol(int x)
{
	int w=0;
	while(x)
	{
		a[++w]=x%10;
		x/=10;
	}
	return dfs(w,0,1);
}
int main()
{
	int l,r;
	l=read();r=read();
	memset(dp,-1,sizeof(dp));
	while(l&&r)
	{
		printf("%d\n",sol(r)-sol(l-1));
		l=read();r=read();
	}
	return 0;
}
标签:sans show input other 安全 答案 reg select family
原文地址:http://www.cnblogs.com/charlotte-o/p/7608052.html