题目概述
Nya数有
X
个
解题报告
对于我这种英语盲……英文题面容易漏条件……题目要求
定义
f[i][x][y]
表示选了
i
位有
好像有非二分的线性求第
示例程序
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int maxn=20,maxx=20,maxy=20;
int T,X,Y,te,a[maxn+5];LL l,r,K,f[maxn+5][maxx+5][maxy+5];
LL Solve(int i,int x,int y,bool fl)
{
if (x<0||y<0) return 0;if (!i) return !x&&!y;if (!fl&&~f[i][x][y]) return f[i][x][y];
int MAX;LL ans=0;if (fl) MAX=a[i]; else MAX=9;
for (int j=0;j<=MAX;j++) ans+=Solve(i-1,x-(j==4),y-(j==7),fl&&j==MAX);
if (!fl) f[i][x][y]=ans;return ans;
}
inline LL Count(LL x)
{
a[0]=0;do a[++a[0]]=x%10,x/=10; while (x);
return Solve(a[0],X,Y,true);
}
int main()
{
freopen("program.in","r",stdin);
freopen("program.out","w",stdout);
memset(f,255,sizeof(f));scanf("%d",&T);
for (int t=1;t<=T;t++)
{
printf("Case #%d:\n",t);
scanf("%lld%lld%d%d",&l,&r,&X,&Y);
for (scanf("%d",&te);te;te--)
{
scanf("%lld",&K);LL L=l,R=r;
for (LL mid=L+(R-L>>1);L<=R;mid=L+(R-L>>1))
if (Count(mid)-Count(l)>=K) R=mid-1; else L=mid+1;
if (L<=r) printf("%lld\n",L); else puts("Nya!");
}
}
return 0;
}