【HDU 2089】不要62

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2089

还是数位dp

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int MAXN = 10;

int f[MAXN][MAXN];

inline void prework(){
	for (int i=0;i<=9;i++) f[1][i] = (i != 4);
	for (int k=2;k<=6;k++) {
		for (int i=0;i<=9;i++) {
			if (i == 4) continue;
			else for (int j=0;j<=9;j++) 
				if (i == 6 && j == 2) continue;
				else f[k][i] += f[k-1][j];
		}
	}
}

inline int cal(int w){
	if (!w) return 0;
	
	int ret=0,tot=0,arr[MAXN];
	memset(arr,0,sizeof(arr));
	while (w) arr[++tot] = w % 10, w /= 10;
	
	for (int i=tot-1;i;i--) for (int j=1;j<=9;j++) ret += f[i][j];
	for (int i=tot;i;i--) {
		for (int j=(i==tot?1:0);j<arr[i];j++) 
			if (arr[i+1] == 6 && j == 2) continue;
			else ret += f[i][j];
		if ((arr[i] == 2 && arr[i+1] == 6) || arr[i] == 4) break;
		else if (i == 1) ret ++;
	}
	return ret;
} 

int main(){
	prework(); int a,b;
	while (scanf("%d%d",&a,&b) && (a || b)) 
		printf("%d\n",cal(b)-cal(a-1));	
	return 0;
}

26 thoughts to “【HDU 2089】不要62”

  1. You have made some decent points there. I checked on the internet
    for additional information about the issue and found most
    individuals will go along with your views on this website.

  2. Thanks for the auspicious writeup. It in truth was a amusement account
    it. Look complicated to more introduced agreeable from you!
    However, how can we communicate?

  3. Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is fundamental and all.

    But imagine if you added some great graphics or video clips to give your posts more, “pop”!
    Your content is excellent but with pics and video clips, this website could definitely be one
    of the most beneficial in its field. Very good blog!

  4. Its like you read my mind! You seem to know a lot about this,
    like you wrote the book in it or something. I think that
    you could do with a few pics to drive the message home a bit,
    but other than that, this is wonderful blog. A great read.
    I’ll certainly be back.

  5. Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that automatically tweet my newest twitter
    updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like
    this. Please let me know if you run into anything. I truly enjoy reading your
    blog and I look forward to your new updates.

  6. Hello there, I found your web site by way of Google even as
    searching for a comparable matter, your site came up,
    it appears to be like great. I’ve bookmarked it in my
    google bookmarks.
    Hello there, just turned into aware of your blog thru Google, and found that it is truly informative.
    I am going to be careful for brussels. I will appreciate in case you continue this
    in future. A lot of other folks will likely be benefited out of your writing.
    Cheers!

  7. Greetings, I believe your web site might be having browser compatibility
    problems. When I look at your blog in Safari, it looks fine but when opening in I.E., it has some overlapping issues.
    I merely wanted to give you a quick heads up!
    Apart from that, fantastic site!

  8. I would like to thank you for the efforts you have put in penning this
    site. I’m hoping to view the same high-grade content from you
    later on as well. In fact, your creative writing abilities
    has encouraged me to get my very own website now 😉

  9. Good site you have here.. It’s difficult to find good quality writing like yours these
    days. I honestly appreciate people like you! Take care!!

  10. Good day I am so thrilled I found your weblog, I really found you by error, while I was searching on Askjeeve for
    something else, Nonetheless I am here now and would just like to say cheers for
    a marvelous post and a all round enjoyable blog (I also love the
    theme/design), I don’t have time to browse it all at the
    moment but I have book-marked it and also added your RSS feeds,
    so when I have time I will be back to read more, Please do keep
    up the excellent work.

  11. Normally I don’t read post on blogs, but I wish
    to say that this write-up very compelled me to try and do so!
    Your writing taste has been amazed me. Thanks, quite nice post.

  12. Great beat ! I wish to apprentice while you amend your site, how can i subscribe for a blog web site?
    The account helped me a acceptable deal. I had been a little bit
    acquainted of this your broadcast offered bright clear concept

  13. The heart of your writing whilst appearing reasonable in the beginning, did not settle well with me personally after some time. Someplace within the paragraphs you managed to make me a believer unfortunately only for a while. I nevertheless have got a problem with your leaps in assumptions and one would do nicely to fill in those gaps. When you can accomplish that, I will definitely be fascinated.

Leave a Reply

Your email address will not be published. Required fields are marked *