码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-11-02 20:08:39      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:img   splay   -128   printf   gic   cli   ==   swap   scanf   

带飞网址 ?

 

专题十 匹配问题 
√ 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 }
View Code

 

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

标签:img   splay   -128   printf   gic   cli   ==   swap   scanf   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!