程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 1693 Eat the Trees (插頭dp入門)

hdu 1693 Eat the Trees (插頭dp入門)

編輯:C++入門知識

hdu 1693 Eat the Trees (插頭dp入門)


Eat the Trees

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

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 Z喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vciAxKSBzZXBhcmF0ZWQgYnkgYSBzcGFjZS4gTnVtYmVyIDAgbWVhbnMgYSBjZWxsIHdoaWNoIGhhcyBubyB0cmVlcyBhbmQgbnVtYmVyIDEgbWVhbnMgYSBjZWxsIHRoYXQgaGFzIGV4YWN0bHkgb25lIHRyZWUuPGJyPgoKIAo8YnI+Ck91dHB1dApGb3IgZWFjaCBjYXNlLCB5b3Ugc2hvdWxkIHByaW50IHRoZSBkZXNpcmVkIG51bWJlciBvZiB3YXlzIGluIG9uZSBsaW5lLiBJdCBpcyBndWFyYW50ZWVkLCB0aGF0IGl0IGRvZXMgbm90IGV4Y2VlZCAyPHN1cD42Mzwvc3VwPiCoQyAxLiBVc2UgdGhlIGZvcm1hdCBpbiB0aGUgc2FtcGxlLgogCjxicj4KU2FtcGxlIElucHV0Cgo8cHJlIGNsYXNzPQ=="brush:java;">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 2008 “Sunline Cup” National Invitational Contest

題意: 給n*m的方格,有些方格有障礙,問有多少種方式能使所有的非障礙點都在某個環上,環可以有多個。

思路: 插頭dp入門,按照點來轉移,dp[i][j][k]表示到i行j列的時候,輪廓線上的插頭狀態為k時候的種類數,有6中情況,劃一劃就能知道怎樣轉移了,注意行與行之間單獨轉移,每行末尾不能有右插頭。
感想: dp如此之菜,插頭dp就先放放了,先把其他的搞好,到一定階段了再來學習吧。
代碼:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define maxn 205
#define MAXN 100005
#define mod 100000000
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
using namespace std;

ll n,m,ans,cnt,tot,flag;
ll mp[12][12],dp[12][12][1<<12];

void solve()
{
    ll i,j,k,t;
    ll up,down,left,right;
    tot=(1<

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved