http://acm.hdu.edu.cn/showproblem.php?pid=4352
数位DP套状压DP再套LIS
整个人都DP啦
//#define _TEST _TEST
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
/************************************************
Code By willinglive Blog:http://willinglive.cf
************************************************/
#define rep(i,l,r) for(int i=l,___t=(r);i<=___t;i++)
#define per(i,r,l) for(int i=r,___t=(l);i>=___t;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define LL long long
#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)
inline const LL read()
{LL r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
/
LL k;
int bit[20];
LL dp[20][1<<10][11];
int bit_cnt[1<<10];
/
inline int Bit_cnt(int x)
{
if(~bit_cnt[x]) return bit_cnt[x];
int res=0;
for(;x;x-=x&-x) res++;
return bit_cnt[x]=res;
}
int getS(int S,int x)
{
rep(i,x,9) if(S&(1<<i)) return (S^(1<<i))|(1<<x);
return S|(1<<x);
}
LL dfs(int pos,int S,bool limit,bool zero)
{
if(!pos) return Bit_cnt(S)==k;
LL tmp=dp[pos][S][k];
if(!limit&&~tmp) return tmp;
LL ans=0;
int upp=limit?bit[pos]:9;
rep(i,0,upp)
{
if(zero&&!i) ans+=dfs(pos-1,0,limit&&i==upp,1);
else ans+=dfs(pos-1,getS(S,i),limit&&i==upp,0);
}
if(!limit) dp[pos][S][k]=ans;
return ans;
}
LL cal(LL n)
{
for(*bit=0;n;n/=10) bit[++*bit]=n%10;
return dfs(*bit,0,1,1);
}
/
void solve()
{
MS(dp,-1); MS(bit_cnt,-1);
rep(cases,1,read())
{
printf("Case #%d: ",cases);
LL l,r;
l=read(); r=read(); k=read();
printf("%I64d\n",cal(r)-cal(l-1));
}
}
/
int main()
{
#ifndef _TEST
freopen("std.in","r",stdin); freopen("std.out","w",stdout);
#endif
solve();
return 0;
}