zoukankan      html  css  js  c++  java
  • 匹配注意HDU 1693(Eat the Trees不用匹配的插头Dp)

    文章结束给大家来个程序员笑话:[M]

        

    Eat the Trees

        Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1908    Accepted Submission(s): 912

        

    Problem Description

        

    Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a strong hero in the first period of the game. When the game goes to end however, Pudge is not a strong hero any more.
    So Pudge’s teammates give him a new assignment—Eat the Trees!

    The trees are in a rectangle N * M cells in size and each of the cells either has exactly one tree or has nothing at all. And what Pudge needs to do is to eat all trees that are in the cells.
    There are several rules Pudge must follow:
    I. Pudge must eat the trees by choosing a circuit and he then will eat all trees that are in the chosen circuit.
    II. The cell that does not contain a tree is unreachable, e.g. each of the cells that is through the circuit which Pudge chooses must contain a tree and when the circuit is chosen, the trees which are in the cells on the circuit will disappear.
    III. Pudge may choose one or more circuits to eat the trees.

    Now Pudge has a question, how many ways are there to eat the trees?
    At the picture below three samples are given for N = 6 and M = 3(gray square means no trees in the cell, and the bold black line means the chosen circuit(s))

    匹配和注意

        

     

        

    Input

        

    The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
    For each case, the first line contains the integer numbers N and M, 1<=N, M<=11. Each of the next N lines contains M numbers (either 0 or 1) separated by a space. Number 0 means a cell which has no trees and number 1 means a cell that has exactly one tree.

        

     

        

    Output

        

    For each case, you should print the desired number of ways in one line. It is guaranteed, that it does not exceed 2 63 – 1. Use the format in the sample.

        

     

        

    Sample Input
    2 6 3 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 2 4 1 1 1 1 1 1 1 1
     

        

    Sample Output
    Case 1: There are 3 ways to eat the trees. Case 2: There are 2 ways to eat the trees.
        每日一道理
    成熟是一种明亮而不刺眼的光辉,一种圆润而不腻耳的音响,一种不需要对别人察颜观色的从容,一种终于停止了向周围申诉求告的大气,一种不理会哄闹的微笑,一种洗刷了偏激的淡漠,一种无须声张的厚实,一种并不陡峭的高度。
     

        

    Source

        

        

     

        

    Recommend

        

    wangye

        

     

        


        

    第一题插头Dp^_^

        

    首先这题不必匹配

        

    然后这题图小好存不必滚

        

    再然后只用分4种情况向后转

        

    勉强不 算插头Dp呢

        


        


    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    #include<cmath>
    #include<cctype>
    using namespace std;
    #define For(i,n) for(int i=1;i<=n;i++)
    #define Rep(i,n) for(int i=0;i<n;i++)
    #define Fork(i,k,n) for(int i=k;i<=n;i++)
    #define ForD(i,n) for(int i=n;i;i--)
    #define Forp(x) for(int p=pre[x];p;p=next[p])
    #define RepD(i,n) for(int i=n;i>=0;i--)
    #define MAXN (12+10)
    int T,bin[MAXN]={0,1};
    __int64 ans=0,f[MAXN][MAXN][1<<13+1]; //hdu不能用long long
    int a[MAXN][MAXN]={0},n,m;
    int main()
    {
    	freopen("hdu1693.in","r",stdin);
    	Fork(i,2,13) bin[i]=bin[i-1]<<1;
    	scanf("%d",&T);
    	For(tt,T)
    	{
    		ans=0;
    		scanf("%d%d",&n,&m);
    		For(i,n) For(j,m) scanf("%d",&a[i][j]);
    		Rep(i,n+1) Rep(j,m+1) Rep(k,1+(1<<m+2)) f[i][j][k]=0; 
    		f[1][0][0]=1;
    		For(i,n) 
    		{
    			if (i>1)
    			{
    				Rep(k,1<<m+1)
    				f[i][0][k<<1]=f[i-1][m][k]; //向下行转移上一行最右的竖线挪到最左
    			}
    			Rep(j,m)
    			{
    				if (i==n&&j==m) break;
    				Rep(k,1<<(m+1))
    				{
    					if (!f[i][j][k]) continue;
    					int l=j+1,up=j+2;
    					bool b1=bin[l]&k,b2=bin[up]&k;
    					if (f[i][j][k])
    					{
    						if (!a[i][j+1]) 
    						{
    							if (b1||b2) continue;
    							f[i][j+1][k]+=f[i][j][k]; //注意斟酌挖空
    						}
    						else if (b1&&b2) f[i][j+1][k-bin[l]-bin[up]]+=f[i][j][k];
    						else if (b1||b2) f[i][j+1][k]+=f[i][j][k],f[i][j+1][k^bin[l]^bin[up]]+=f[i][j][k];
    						else f[i][j+1][k+bin[l]+bin[up]]+=f[i][j][k];
    					}
    				}
    			}
    		}
    		ans=f[n][m][0];
    		printf("Case %d: There are %I64d ways to eat the trees.\n",tt,ans);
    	}
    	return 0;
    }



    文章结束给大家分享下程序员的一些笑话语录: 那是习惯决定的,一直保持一个习惯是不好的!IE6的用户不习惯多标签,但是最终肯定还是得转到多标签的浏览器。历史(软件UI)的进步(改善)不是以个人意志(习惯)为转移的!

    --------------------------------- 原创文章 By 匹配和注意 ---------------------------------

  • 相关阅读:
    [洛谷P2745] [USACO5.3]窗体面积Window Area
    [洛谷P2751] [USACO4.2]工序安排Job Processing
    [洛谷P2738] [USACO4.1]篱笆回路Fence Loops
    [洛谷P4609] [FJOI2016]建筑师
    [洛谷P3228] [HNOI2013]数列
    解决Qt5使用SSL的“qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method”错误
    qt查看是否支持SSL
    qt获取依赖的openssl的版本
    qt关闭ssl验证,解决不能正常使用自签署ssl证书API的问题
    使用OpenSSL创建HTTPS所使用的SSL证书
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3095766.html
Copyright © 2011-2022 走看看