zoukankan      html  css  js  c++  java
  • [BZOJ] ]1026: [SCOI2009]windy数

    需要记录的信息有:做到了第几位,上一位的数字,是否随便填

    记搜实现起来实在是方便,数位DP应该不会卡常数

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    
    inline int rd(){
      int ret=0,f=1;char c;
      while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
      while(isdigit(c))ret=ret*10+c-'0',c=getchar();
      return ret*f;
    }
    #define space() putchar(' ')
    #define nextline() putchar('
    ')
    void pot(int x){if(!x)return;pot(x/10);putchar('0'+x%10);}
    void out(int x){if(!x)putchar('0');if(x<0)putchar('-'),x=-x;pot(x);}
    
    const int MAXN = 22;
    
    int f[MAXN][MAXN];
    
    int a[MAXN],top;
    int dfs(int dp,int lst,bool lim){
    	if(dp==0)return 1;
    	if(!lim&&lst>=0&&f[dp][lst]!=-1)return f[dp][lst];
    	int ret=0,up=(lim?a[dp]:9),pos;
    	for(int i=0;i<=up;i++){
    		if(abs(i-lst)<2) continue;	
    		pos=i;
    		if(i==0&&lst==-3) pos=-3;
    		ret+=dfs(dp-1,pos,lim&(i==up));
    	}
    	if(!lim&&lst>=0) f[dp][lst]=ret;
    	return ret;
    }
    
    int solve(int x){
    	top=0;
    	while(x){
    		a[++top]=x%10;
    		x/=10;
    	}
    	memset(f,-1,sizeof(f));
    	return dfs(top,-3,1);
    }
    
    int main(){
    	int L,R;
    	L=rd();R=rd();
    	out(solve(R)-solve(L-1));
    	return 0;
    }
    
    未经许可,禁止搬运。
  • 相关阅读:
    js实现选择切换
    Jquery操作select
    Mybatis 高级结果映射 ResultMap Association Collection
    jQuery的一些特性和用法
    利用JSONP解决AJAX跨域问题的原理与jQuery解决方案
    List转成Array 连个Array比较
    3.15
    Get 和 Post 方法的选择和URL的设计
    fd
    如何维护一个1000 IP的免费代理池
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9815344.html
Copyright © 2011-2022 走看看