#include#include#include#include" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

【BZOJ】1833: [ZJOI2010]count 數(shù)字計數(shù)(數(shù)位

系統(tǒng) 1864 0

http://www.lydsy.com/JudgeOnline/problem.php?id=1833

數(shù)位dp什么的最惡心了。

dfs時注意考慮兩種邊界,一種是此時正好在這個數(shù)上,那么答案應(yīng)該加的是后邊的數(shù)+1+dfs

否則就加10^(x-1)+dfs;這兩個是顯然的。自己多想想就懂了

具體看代碼:

      #include <cstdio>

#include <cstring>

#include <cmath>

#include <string>

#include <iostream>

#include <algorithm>

#include <queue>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

#define for1(i,a,n) for(int i=(a);i<=(n);++i)

#define for2(i,a,n) for(int i=(a);i<(n);++i)

#define for3(i,a,n) for(int i=(a);i>=(n);--i)

#define for4(i,a,n) for(int i=(a);i>(n);--i)

#define CC(i,a) memset(i,a,sizeof(i))

#define read(a) a=getint()

#define print(a) printf("%d", a)

#define dbg(x) cout << (#x) << " = " << (x) << endl

#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }

#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl

inline const ll getint() { 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; }

inline const int max(const int &a, const int &b) { return a>b?a:b; }

inline const int min(const int &a, const int &b) { return a<b?a:b; }



ll f[100], c[100], a[100], p[100];



ll dfs(int x, int dig, int front, int line) {

	if(!x) return 0;

	if(!front && !line && f[x]!=-1) return f[x];

	ll last=(line?a[x]:9), tot=0;

	for1(i, 0, last) {

		if(front && i==0) tot+=dfs(x-1, dig, 1, line&&i==last);

		else if(i==dig) {

			if(i==last && line) tot+=c[x-1]+1+dfs(x-1, dig, 0, line&&i==last); //正好在這個數(shù)上

			else tot+=p[x-1]+dfs(x-1, dig, 0, line&&i==last);

		}

		else tot+=dfs(x-1, dig, 0, line&&i==last);

	}

	if(!front && !line) f[x]=tot;

	return tot;

}

ll getans(ll x, int dig) {

	CC(f, -1);

	ll t=x; int len=0;

	while(t) a[++len]=t%10, t/=10, c[len]=c[len-1]+a[len]*p[len-1];

	return dfs(len, dig, 1, 1);

}

int main() {

	ll a=getint(), b=getint();

	p[0]=1; for1(i, 1, 15) p[i]=p[i-1]*10;

	rep(i, 9) printf("%lld ", getans(b, i)-getans(a-1, i));

	printf("%lld\n", getans(b, 9)-getans(a-1, 9));

	return 0;

}


    

?

?


?

?

Description

給定兩個正整數(shù)a和b,求在[a,b]中的所有整數(shù)中,每個數(shù)碼(digit)各出現(xiàn)了多少次。

Input

輸入文件中僅包含一行兩個整數(shù)a、b,含義如上所述。

Output

輸出文件中包含一行10個整數(shù),分別表示0-9在[a,b]中出現(xiàn)了多少次。

Sample Input

1 99

Sample Output

9 20 20 20 20 20 20 20 20 20

HINT

30%的數(shù)據(jù)中,a<=b<=10^6;
100%的數(shù)據(jù)中,a<=b<=10^12。

Source

【BZOJ】1833: [ZJOI2010]count 數(shù)字計數(shù)(數(shù)位dp)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产成人精品第一区二区 | 牛牛影视午夜免费福利 | 日韩精品中文字幕在线观看 | 伊人久久大香线蕉亚洲 | 波多野结衣一区在线观看 | 亚洲一区欧美 | 亚洲欧美日韩中文字幕网址 | 特黄日韩免费一区二区三区 | 91丨九色丨蝌蚪 | 狠狠干天天干 | 久久久毛片 | 男人的天堂视频 | 亚洲高清视频一区 | aⅴ免费在线观看 | 天天操天天插 | 大伊香蕉在线精品不卡视频 | 欧美久久久久欧美一区 | 亚洲欧美精品久久 | h视频在线观看网站 | 99久久免费精品国产免费 | 天天干天天插天天操 | 欧美ⅹxxxx18性欧美 | 国产在线播放91 | 91久久综合九色综合欧美亚洲 | 黄色网在线 | 欧美亚洲国产成人高清在线 | 老司机永久免费网站在线观看 | 九九99热 | 香蕉视频日本 | 青青青视频精品中文字幕 | 免费观看黄a一级视频日本 免费观看黄色 | 亚洲国产成人精品女人久久久 | 四虎国产精品永久地址99 | 久久日韩| 天天干天天干天天干天天 | 国产波多野结衣中文在线播放 | 亚洲综合久久久久久中文字幕 | 热久久视久久精品18国产 | 精品视频免费在线 | 天天干天天干天天干天天干天天干 | 伊人影院在线视频 |