【HDU 4624】Endless Spin

相关链接

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4624
神犇题解Ⅰ:http://www.cnblogs.com/chanme/p/4869377.html
神犇题解Ⅱ:http://blog.csdn.net/beginendzrq/article/details/51331954

解题报告

我们设$f_i$为染色$i$次后还有球没有被染色的概率
那么我们的答案$ans$为: $\sum\limits_{i = 0}^\infty {{f_i}} $

现在考虑如何求$f_i$,我们先来$O(2^n)$暴力容斥
具体来讲,我们枚举染色$i$次后还剩下哪些球为白色
设还有$k$个球为白色,这$k$个球位置分别为$v_1 \sim v_k$
那么单次染色的区间不能包含这$k$个位置,设合法的方案数为$A$
那么单次染色符合条件的概率$P=\frac{A}{\frac{n(n-1)}{2}}$
那么$i$次都符合要求的概率就是$P^i$
于是对于$f_i$来讲,贡献为$P^i \cdot (-1)^{k-1}$
这种情况对于答案$ans$的贡献为$(-1)^{k-1}\sum\limits_{i=0}^{\infty}{P^i}=\frac{(-1)^{k-1}}{1-P}$

现在考虑优化容斥的过程
我们发现每一种具体的方案对于答案的贡献只与剩余球的数量的奇偶性和$A$有关
于是我们可以搞一个状态为$O(n^4)$,转移为$O(1)$的DP来优化容斥

Code

这份代码在我本地跑出来是对的,但交上去就wa
于是只能打了一份表交上去:http://paste.ubuntu.com/24448347/

#include<bits/stdc++.h>
#define LL long long
#define LDB __float128
using namespace std;

const int N = 51;
const int M = N * N;

int n,ww,pp;
LL f[2][N][M][2]; 
LDB ans;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int main() {
	for (int T=read();T;T--) {
		ans = ww = 0; pp = 1;
		memset(f,0,sizeof(f));
		f[pp][0][0][0] = 1;
		n = read();
		for (int i=0;i<n;i++,ww^=1,pp^=1) { 
			memset(f[ww],0,sizeof(f[ww]));
			for (int j=0;j<=i;j++) {
				for (int k=i*i;~k;k--) {
					for (int p=0;p<=1;p++) {
						if (f[pp][j][k][p]) {
							f[ww][0][k+j*(j+1)/2][p^(j&1)] += f[pp][j][k][p];
							f[ww][j+1][k][p] += f[pp][j][k][p]; 
						}
					}
				}
			}
		}
		for (int j=0;j<=n;j++) {
			for (int k=n*n;~k;k--) {
				for (int p=0;p<=1;p++) {
					if (!f[pp][j][k][p]) continue;
					int v = k + j * (j + 1) / 2, t = p ^ (j & 1);
					LDB tmp = ((v < n * (n + 1) / 2)? ((LDB)v / (n * (n + 1) / 2 - v)): 0);
					if ((n-t)&1) ans += tmp * f[pp][j][k][p];
					else ans -= tmp * f[pp][j][k][p];
				}
			}
		}
		ans += 1; 
		printf("%.15Lf\n",(long double)ans);
	}
	return 0;
}

相关拓展

当然这题还可以改成:如果染到$k$个球都为黑色了就停止,询问停止时的期望步数
例题可以参考:凯旋三兵

84 thoughts to “【HDU 4624】Endless Spin”

  1. Wow that was strange. I just wrote an very long comment but after I clicked submit my
    comment didn’t show up. Grrrr… well I’m not
    writing all that over again. Anyway, just wanted to say excellent blog!

  2. Sweet blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Cheers

  3. I do not know whether it’s just me or if perhaps everyone else experiencing issues with your site.

    It seems like some of the written text on your posts are running off the screen. Can someone else please comment
    and let me know if this is happening to them as well? This might be a problem with my
    web browser because I’ve had this happen previously.

    Cheers

  4. Aw, this was an exceptionally nice post. Finding the time and actual effort to create a superb article… but what can I
    say… I procrastinate a lot and don’t manage to get anything done.

  5. After I originally commented I appear to have clicked the -Notify me when new comments are added-
    checkbox and now each time a comment is added I recieve four emails
    with the same comment. There has to be a way you are able to remove me from that service?
    Thanks a lot!

  6. I’ve been surfing online more than 3 hours today, yet I never found
    any interesting article like yours. It is pretty worth enough for me.
    Personally, if all web owners and bloggers made good
    content as you did, the net will be a lot more useful than ever before.

  7. Great post however I was wanting to know if you could write a litte more on this subject?
    I’d be very thankful if you could elaborate a little bit
    more. Bless you!

  8. I seriously love your website.. Pleasant colors &
    theme. Did you create this website yourself?

    Please reply back as I’m wanting to create my very own website
    and want to know where you got this from or just what the
    theme is called. Many thanks!

  9. After I initially left a comment I appear to have clicked the -Notify me when new comments are
    added- checkbox and from now on each time a comment is added I
    receive four emails with the same comment. Perhaps there is a way you can remove me from that service?
    Many thanks!

  10. A person necessarily assist to make critically posts I’d state.
    This is the very first time I frequented your web page
    and to this point? I amazed with the analysis you
    made to create this actual submit extraordinary.

    Magnificent process!

  11. My spouse and I absolutely love your blog and find nearly all of your post’s to
    be just what I’m looking for. can you offer guest writers to write content available for you?
    I wouldn’t mind producing a post or elaborating
    on most of the subjects you write concerning here. Again, awesome blog!

    pof natalielise

  12. Hey there! I know this is kind of off topic but I was wondering if you
    knew where I could locate a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having trouble finding one?
    Thanks a lot! pof natalielise

  13. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web savvy so I’m not 100% positive. Any tips or advice would be
    greatly appreciated. Many thanks

  14. May I simply just say what a comfort to discover someone who truly knows what they’re talking
    about over the internet. You certainly understand how to bring an issue to light and make it important.
    More and more people really need to check this out and understand this side of your story.
    I was surprised that you aren’t more popular because you certainly have the gift.

  15. I’m not sure why but this website is loading very slow for me.
    Is anyone else having this problem or is it a problem on my end?
    I’ll check back later on and see if the problem still exists.

  16. magnificent put up, very informative. I’m wondering why the
    opposite experts of this sector don’t notice this. You should continue your writing.
    I am confident, you’ve a great readers’ base already!

  17. Appreciating the time and energy you put into your website and detailed information you present.
    It’s great to come across a blog every once
    in a while that isn’t the same unwanted rehashed material.
    Wonderful read! I’ve saved your site and I’m including your RSS feeds to my Google account.

  18. I used to be suggested this website through my cousin. I’m no longer positive whether or not
    this submit is written by way of him as no one else know such
    specified about my difficulty. You are wonderful!
    Thanks!

  19. After looking at a number of the blog articles on your web page, I honestly like your way
    of writing a blog. I added it to my bookmark
    webpage list and will be checking back in the near future.
    Take a look at my web site as well and let me know your opinion.

  20. Wonderful blog! I found it while browsing on Yahoo News.

    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Cheers

  21. I absolutely love your website.. Pleasant colors & theme.

    Did you develop this amazing site yourself?
    Please reply back as I’m attempting to create my
    own personal website and would love to find out where you got this from
    or what the theme is named. Cheers!

  22. Its such as you read my mind! You appear to know so much approximately this,
    like you wrote the e book in it or something. I think that you could do with some percent to force
    the message house a little bit, but instead of that, this is magnificent blog.

    An excellent read. I will definitely be back.

  23. Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll just
    sum it up what I wrote and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog writer but I’m still new to the whole thing.

    Do you have any tips and hints for beginner
    blog writers? I’d genuinely appreciate it.

  24. I have learn some just right stuff here. Certainly price bookmarking for revisiting.
    I wonder how so much attempt you place to create the sort
    of magnificent informative website.

  25. I was wondering if you ever considered changing the
    page layout of your website? Its very well written; I love what youve got
    to say. But maybe you could a little more in the way of content so
    people could connect with it better. Youve got an awful lot of text for only having 1 or
    2 pictures. Maybe you could space it out better?

  26. After looking into a number of the blog articles on your
    site, I seriously appreciate your technique of blogging. I bookmarked it to my bookmark
    website list and will be checking back soon. Please check out my web site as
    well and let me know your opinion.

  27. Does your blog have a contact page? I’m having trouble locating it but,
    I’d like to send you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing.
    Either way, great website and I look forward to seeing it expand over
    time.

  28. Very good blog you have here but I was wanting to know if
    you knew of any user discussion forums that cover the same
    topics talked about in this article? I’d really like to be a part of community where I can get suggestions from other knowledgeable people
    that share the same interest. If you have any suggestions, please let me know.
    Thanks!

  29. I really like your blog.. very nice colors & theme. Did you make this
    website yourself or did you hire someone to do
    it for you? Plz respond as I’m looking to construct
    my own blog and would like to find out where u got this from.
    thank you

  30. It is appropriate time to make some plans for the future and it is time to be
    happy. I’ve read this post and if I could I want to suggest you few interesting things or suggestions.
    Maybe you can write next articles referring to this article.

    I want to read more things about it!

  31. Hi there would you mind letting me know which hosting company you’re utilizing?
    I’ve loaded your blog in 3 different web browsers and I must say this blog loads a lot faster then most.
    Can you suggest a good hosting provider at a honest price? Kudos, I appreciate it!

  32. I just like the helpful information you supply to your articles.
    I will bookmark your weblog and check once more right here regularly.
    I am quite certain I’ll be told many new stuff proper here!
    Good luck for the next!

  33. Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts.
    Anyway I will be subscribing to your feeds and even I achievement you access
    consistently rapidly.

  34. Hello! I could have sworn I’ve been to this website before but after browsing through some of the posts I realized it’s
    new to me. Regardless, I’m certainly delighted I found
    it and I’ll be bookmarking it and checking back often!

  35. Unquestionably believe that which you said. Your favorite justification seemed
    to be on the internet the simplest thing to be aware of.
    I say to you, I definitely get annoyed while people consider worries that they plainly don’t know about.
    You managed to hit the nail upon the top and also defined out
    the whole thing without having side effect , people can take a signal.
    Will likely be back to get more. Thanks

  36. Hey! Would you mind if I share your blog with my myspace group?
    There’s a lot of folks that I think would really appreciate
    your content. Please let me know. Thank you

  37. Your style is really unique compared to other
    folks I’ve read stuff from. I appreciate you for posting when you’ve got the opportunity, Guess I will just
    bookmark this site.

  38. You could certainly see your enthusiasm in the article you write.

    The sector hopes for more passionate writers like you who are not afraid to mention how they believe.

    At all times follow your heart.

  39. What i don’t realize is actually how you are now not really a lot more well-preferred
    than you may be now. You are so intelligent. You know
    thus considerably when it comes to this topic, produced me individually believe it from numerous numerous angles.

    Its like men and women are not interested unless it is something to accomplish with Lady gaga!

    Your individual stuffs excellent. All the time take care of it up!

  40. Awesome blog! Is your theme custom made or did you download
    it from somewhere? A theme like yours with a few simple
    tweeks would really make my blog stand out. Please let me
    know where you got your theme. Thanks a lot

  41. We are a group of volunteers and starting a new scheme in our community.

    Your site offered us with valuable info to work on. You’ve done a formidable job
    and our whole community will be grateful to you.

  42. Link exchange is nothing else however it is
    simply placing the other person’s web site
    link on your page at proper place and other person will
    also do similar for you.

  43. Heya i’m for the first time here. I found this board and I find It really useful & it helped me out much.

    I hope to give something back and aid others like
    you aided me.

  44. Somebody necessarily lend a hand to make significantly articles I
    might state. That is the first time I frequented your web page
    and so far? I amazed with the research you made to make this actual post extraordinary.
    Great activity!

  45. What’s Happening i am new to this, I stumbled upon this I have found It positively helpful and it has helped me out loads. I hope to contribute & help other users like its aided me. Good job.

Leave a Reply

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