[kuangbin]带你飞之'匹配问题'专题

带飞网址 ?

专题十 匹配问题 
√ HDU 1045 Fire Net
HDU 2444 The Accomodation of Students
HDU 1083 Courses
HDU 1281 棋盘游戏
HDU 2819 Swap
HDU 2389 Rain on your Parade
HDU 4185 Oil Skimming
POJ 3020 Antenna Placement
HDU 1054 Strategic Game
HDU 1151 Air Raid
POJ 2594 Treasure Exploration
HDU 3829 Cat VS Dog
POJ 2289 Jamie‘s Contact Groups
POJ 2112 Optimal Milking
POJ 3189 Steady Cow Assignment
HDU 2255 奔小康赚大钱
HDU 3488 Tour
URAL 1099 Work Scheduling
HDU 4687 Boke and Tsukkomi

// hdu 1045

 1 #include<cstdio>
 2
 3 int n, maxn;
 4 char G[4][4];
 5
 6 bool read_input() {
 7     if(scanf("%d", &n) == 1 && !n) return false;
 8     for(int i = 0; i != n; ++i) {
 9         scanf("%s", G[i]);
10     }
11     return true;
12 }
13
14 bool can_put(int r, int c) {
15     if(G[r][c] == ‘X‘) return false;
16     int i, j;
17     j = c;
18     while(j >= 0 && G[r][j] != ‘X‘) {
19         if(j != c && G[r][j] == ‘1‘) return false;
20         --j;
21     }
22     j = c;
23     while(j != n && G[r][j] != ‘X‘) {
24         if(j != c && G[r][j] == ‘1‘) return false;
25         ++j;
26     }
27     i = r;
28     while(i >= 0 && G[i][c] != ‘X‘) {
29         if(i != r && G[i][c] == ‘1‘) return false;
30         --i;
31     }
32     i = r;
33     while(i != n && G[i][c] != ‘X‘) {
34         if(i != r && G[i][c] == ‘1‘) return false;
35         ++i;
36     }
37     return true;
38 }
39
40 void dfs(int r, int c, int v) {
41     if(r == n) {
42         if(v > maxn) maxn = v;
43         return;
44     }
45     if(can_put(r, c)) {
46         G[r][c] = ‘1‘;
47         if(c == n-1) dfs(r+1, 0, v+1);
48         else dfs(r, c+1, v+1);
49         G[r][c] = ‘.‘;
50     }
51     if(c == n-1) dfs(r+1, 0, v);
52     else dfs(r, c+1, v);
53 }
54
55
56 int main() {
57     while(read_input()) {
58         maxn = 0;
59         dfs(0, 0, 0);
60         printf("%d\n", maxn);
61     }
62     return 0;
63 }

[kuangbin]带你飞之'匹配问题'专题

原文地址:https://www.cnblogs.com/pupil-xj/p/11783547.html

时间: 2024-07-29 02:56:47

[kuangbin]带你飞之'匹配问题'专题的相关文章

[kuangbin]带你飞之&#39;线段树&#39;专题(未完成)

// 带飞网址 https://vjudge.net/article/187 专题七 线段树 HDU 1166 敌兵布阵HDU 1754 I Hate It√ POJ 3468 A Simple Problem with IntegersPOJ 2528 Mayor's postersHDU 1698 Just a HookZOJ 1610 Count the ColorsPOJ 3264 Balanced LineupHDU 4027 Can you answer these queries?

「kuangbin带你飞」专题十八 后缀数组

layout: post title: 「kuangbin带你飞」专题十八 后缀数组 author: "luowentaoaa" catalog: true tags: - kuangbin - 字符串 - 后缀数组 传送门 倍增法 struct DA{ bool cmp(int *r,int a,int b,int l){ return r[a]==r[b]&&r[a+l]==r[b+l]; } int t1[maxn],t2[maxn],c[maxn]; int r

「kuangbin带你飞」专题二十二 区间DP

layout: post title: 「kuangbin带你飞」专题二十二 区间DP author: "luowentaoaa" catalog: true tags: - kuangbin - 区间DP - 动态规划 传送门 B.LightOJ - 1422 Halloween Costumes 题意 按顺序参加舞会,参加一个舞会要穿一种衣服,可以在参加完一个舞会后套上另一个衣服再去参加舞会,也可以在参加一个舞会的时候把外面的衣服脱了,脱到合适的衣服,但是脱掉的衣服不能再穿,参加完

kuangbin带你飞专题一 简单搜索 题解

目录 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题一 简单搜索 总结:用时2天半终于把这个专题刷完了 对于最基础的dfs bfs 路径打印 状态转移也有了一点自己些微的理解 其实2天半可以压缩到1天半的 主要是自己太懒了...慢慢加油刷bin神的专题呀 从大二下学期开始学算法 一开始就知道这个专题 一开始对于这个专题里的所有问题感觉都好难啊..就直接放弃了 看lrj的书 现在看到这个专题还挺唏嘘的吧 突然觉得思维和想法也不是很难 果然是那个时候心不静&还是储量不够吗

「kuangbin带你飞」专题十二 基础DP

layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathjax: true - kuangbin - 动态规划 传送门 A.HDU1024 Max Sum Plus Plus 题意 给你N个数,然后你分成M个不重叠部分,并且这M个不重叠部分的和最大. 思路 动态规划最大m字段和,dp数组,dp[i][j]表示以a[j]结尾的,i个字段的最大和 两种情况:1.第a[j

「kuangbin带你飞」专题二十 斜率DP

layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathjax: true - kuangbin - 动态规划 - 斜率DP 传送门 A.HDU - 3507 Print Article 题意 就是输出序列a[n],每连续输出的费用是连续输出的数字和的平方加上常数M 让我们求这个费用的最小值. 题解 概率DP的入门题,把我搞得要死要活的. 首先dp[i]表示输出前i

[kuangbin带你飞]专题十六 KMP &amp; 扩展KMP &amp; Manacher :G - Power Strings POJ - 2406(kmp简单循环节)

[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher G - Power Strings POJ - 2406 题目: Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of

跟着chengyulala刷题之[kuangbin带你飞]之&#39;并查集&#39;专题/斜眼笑

[kuangbin带你飞] 专题1-23 https://vjudge.net/article/187 专题五 并查集 POJ 2236 Wireless Network  http://poj.org/problem?id=2236POJ 1611 The Suspects  http://poj.org/problem?id=1611HDU 1213 How Many Tables  http://acm.hdu.edu.cn/showproblem.php?pid=1213HDU 3038

[kuangbin带你飞]之&#39;最小生成树 &#39;专题(未完成)

带飞网址: https://vjudge.net/article/187 专题六: POJ 1251 Jungle RoadsPOJ 1287 NetworkingPOJ 2031 Building a Space StationPOJ 2421 Constructing RoadsZOJ 1586 QS NetworkPOJ 1789 Truck HistoryPOJ 2349 Arctic NetworkPOJ 1751 HighwaysPOJ 1258 Agri-NetPOJ 3026 B