【HDU 1693】Eat the Trees

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

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;

const int MAXN = 5000;

LL f[12][12][MAXN];
int MX,n,m,mat[12][12];

int main(){
	int TT; cin>>TT;
	for (int T=1;T<=TT;T++) {
		scanf("%d%d",&m,&n); MX =1<<n+1;
		for (int j=1;j<=m;j++) for (int i=1;i<=n;i++) 
			scanf("%d",&mat[i][j]),memset(f[i][j],0,sizeof(f[i][j]));
		
		
		if (mat[1][1]) f[1][1][3] = 1;
		else f[1][1][0] = 1;
		for (int j=1;j<=m;j++) { 
			for (int i=1;i<n;i++) {
				for (int k=0;k<MX;k++) if (f[i][j][k]) {
					bool up=k&(1<<i+1), left=k&(1<<i);
					if (mat[i+1][j]) {
			 			if (up && left) f[i+1][j][k^(1<<i)^(1<<i+1)] += f[i][j][k];
						else if (up || left) {
							f[i+1][j][k] += f[i][j][k];
							f[i+1][j][k^(1<<i+1)^(1<<i)] += f[i][j][k];	
						} else {
							f[i+1][j][k^(1<<i+1)^(1<<i)] += f[i][j][k];
						}
					} else {
						if (!up && !left) f[i+1][j][k] += f[i][j][k];
					} 
				} 
			}
			for (int k=0;k<MX;k++) if (f[n][j][k] && (k&(1<<n)) == 0) {
				int up = k & 1;
				if (mat[1][j+1]) {
					if (up) {
						f[1][j+1][((k^1)<<1)^1] += f[n][j][k];
						f[1][j+1][((k^1)<<1)^2] += f[n][j][k];
					} else {
						f[1][j+1][(k<<1)^3] += f[n][j][k];
					}
				} else {
					if (!up) f[1][j+1][k<<1] += f[n][j][k];
					else continue;
				}
			}
		}  
		printf("Case %d: There are %I64d ways to eat the trees.\n",T,f[n][m][0]);
	} 
	return 0;
} 

38 thoughts to “【HDU 1693】Eat the Trees”

  1. 971814 137404Its genuinely a cool and valuable piece of info. Im glad that you merely shared this valuable data with us. Please stay us informed like this. Thank you for sharing. 249652

  2. Thanks for another informative site. The
    place else may just I am getting that kind of information written in such a perfect means?

    I have a challenge that I am simply now working on, and I have been at
    the glance out for such info.

  3. 537761 45901Wonderful blog here! Also your website loads up fast! What host are you utilizing? Can I get your affiliate link to your host? I wish my internet site loaded up as fast as yours lol 252941

  4. 434711 174539Admiring the time and effort you put into your site and in depth information you offer. It is great to come across a blog every once in a even though that isnt the same out of date rehashed material. Excellent read! Ive saved your internet site and Im including your RSS feeds to my Google account. 755088

  5. 410428 491528Oh my goodness! a wonderful post dude. Thank you Even so I will probably be experiencing issue with ur rss . Dont know why Can not subscribe to it. Will there be any person finding identical rss difficulty? Anybody who knows kindly respond. Thnkx 283461

  6. Hi, i think that i saw you visited my blog so i came to “return the favor”.I am
    trying to find things to improve my web site!I suppose its ok to use a
    few of your ideas!!

  7. Magnificent beat ! I wish to apprentice at the same time
    as you amend your website, how can i subscribe for a blog site?
    The account helped me a appropriate deal. I had been tiny bit familiar of this your broadcast offered vivid transparent idea

  8. I was suggested this web site by means of my cousin. I’m now not certain whether
    this submit is written by way of him as no one else
    understand such targeted approximately my difficulty. You’re amazing!
    Thank you!

  9. I’m extremely impressed with your writing talents as neatly as with the layout to your weblog.
    Is this a paid theme or did you customize it yourself?
    Either way keep up the nice quality writing, it’s rare to see a
    great weblog like this one these days..

  10. May I just say what a comfort to uncover a person that
    really knows what they are talking about on the internet.

    You certainly understand how to bring a problem to light and make it important.
    A lot more people have to look at this and understand this side of the story.

    It’s surprising you aren’t more popular because
    you definitely possess the gift.

  11. My brother recommended I might like this blog. He was entirely right.
    This post actually made my day. You cann’t imagine simply how much time I had spent for this info!
    Thanks!

  12. Excellent pieces. Keep writing such kind of info on your
    site. Im really impressed by your site.
    Hi there, You have done an excellent job.
    I will certainly digg it and personally suggest to my friends.
    I am sure they will be benefited from this web site.

  13. Hi there! This post could not be written any better! Reading this post reminds me of my old
    room mate! He always kept talking about this. I will forward this post to him.

    Pretty sure he will have a good read. Thanks
    for sharing!

  14. I know this if off topic but I’m looking into starting my own blog and
    was curious 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 internet savvy so I’m not 100% sure. Any recommendations or
    advice would be greatly appreciated. Kudos

  15. Simply desire to say your article is as amazing.
    The clearness to your put up is just nice and i can suppose you’re a professional on this subject.
    Well together with your permission allow me
    to grasp your feed to stay updated with imminent post.
    Thanks a million and please continue the rewarding work.

  16. Generally I don’t read post on blogs, however I would like to say that this
    write-up very pressured me to check out and do so!
    Your writing taste has been surprised me. Thank you, quite nice post.

  17. We’re a group of volunteers and opening a new scheme in our community.
    Your web site provided us with valuable information to work
    on. You’ve done a formidable job and our entire
    community will be thankful to you.

  18. An attention-grabbing discussion is price comment. I believe that it’s best to write extra on this matter, it may not be a taboo subject but generally individuals are not enough to speak on such topics. To the next. Cheers

Leave a Reply

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