【数位DP】【hdu 4352】XHXJ's LIS

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值