# bzoj1028 [JSOI2007]麻将

## 1028: [JSOI2007]麻将

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 1337  Solved: 601
[Submit][Status][Discuss]

## Sample Input

9 4
1 1 2 2 3 3 5 5 5 7 8 8 8

6 7 9

## Source

 1 #include <cstdio>
2 #include <cstring>
3 #include <cstdlib>
4 #include <cmath>
5 #include <deque>
6 #include <vector>
7 #include <queue>
8 #include <iostream>
9 #include <algorithm>
10 #include <map>
11 #include <set>
12 #include <ctime>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
18 #define Rep(i, t) for(int i = (0); i < (t); i++)
19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
20 #define rep(i, x, t) for(int i = (x); i < (t); i++)
21 #define MIT (2147483647)
22 #define INF (1000000001)
23 #define MLL (1000000000000000001LL)
24 #define sz(x) ((int) (x).size())
25 #define clr(x, y) memset(x, y, sizeof(x))
26 #define puf push_front
27 #define pub push_back
28 #define pof pop_front
29 #define pob pop_back
30 #define ft first
31 #define sd second
32 #define mk make_pair
33 inline void SetIO(string Name) {
34     string Input = Name+".in",
35     Output = Name+".out";
36     freopen(Input.c_str(), "r", stdin),
37     freopen(Output.c_str(), "w", stdout);
38 }
39
40 const int N = 410;
41 int n, m, Arr[N];
42 int Ans[N], Tot;
43
44 inline void Input() {
45     scanf("%d%d", &n, &m);
46     For(i, 1, 3*m+1) {
47         int x;
48         scanf("%d", &x);
49         Arr[x]++;
50     }
51 }
52
53 int Tmp[N];
54 inline bool Check(int x) {
55     For(i, 1, n) {
56         For(j, 1, n) Tmp[j] = Arr[j];
57         Tmp[x]++;
58         Tmp[i] -= 2;
59         if(Tmp[i] < 0) continue;
60
61         bool flag = 1;
62         Ford(j, n, 3) {
63             if(Tmp[j] < 0) {
64                 flag = 0;
65                 break;
66             }
67             if(!Tmp[j]) continue;
68             Tmp[j] %= 3;
69             Tmp[j-1] -= Tmp[j];
70             Tmp[j-2] -= Tmp[j];
71             Tmp[j] = 0;
72         }
73         Tmp[1] %= 3, Tmp[2] %= 3;
74         if(Tmp[1] || Tmp[2]) flag = 0;
75
76         if(flag)  return 1;
77     }
78     return 0;
79 }
80
81 inline void Solve() {
82     For(i, 1, n)
83         if(Check(i)) Ans[++Tot] = i;
84
85     if(!Tot) puts("NO");
86     else {
87         For(i, 1, Tot-1) printf("%d ", Ans[i]);
88         printf("%d\n", Ans[Tot]);
89     }
90 }
91
92 int main() {
93     #ifndef ONLINE_JUDGE
94     SetIO("1028");
95     #endif
96     Input();
97     Solve();
98     return 0;
99 }
View Code

 1 #include <cstdio>
2 #include <cstring>
3 #include <cstdlib>
4 #include <cmath>
5 #include <deque>
6 #include <vector>
7 #include <queue>
8 #include <iostream>
9 #include <algorithm>
10 #include <map>
11 #include <set>
12 #include <ctime>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
18 #define Rep(i, t) for(int i = (0); i < (t); i++)
19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
20 #define rep(i, x, t) for(int i = (x); i < (t); i++)
21 #define MIT (2147483647)
22 #define INF (1000000001)
23 #define MLL (1000000000000000001LL)
24 #define sz(x) ((int) (x).size())
25 #define clr(x, y) memset(x, y, sizeof(x))
26 #define puf push_front
27 #define pub push_back
28 #define pof pop_front
29 #define pob pop_back
30 #define ft first
31 #define sd second
32 #define mk make_pair
33 inline void SetIO(string Name) {
34     string Input = Name+".in",
35     Output = Name+".out";
36     freopen(Input.c_str(), "r", stdin),
37     freopen(Output.c_str(), "w", stdout);
38 }
39
40 const int N = 410;
41 int n, m, Arr[N];
42 int Ans[N], Tot;
43
44 inline void Input() {
45     scanf("%d%d", &n, &m);
46     For(i, 1, 3*m+1) {
47         int x;
48         scanf("%d", &x);
49         Arr[x]++;
50     }
51 }
52
53 int Tmp[N];
54 inline bool Check(int x) {
55     For(i, 1, n) {
56         For(j, 1, n+2) Tmp[j] = Arr[j];
57         Tmp[x]++;
58         Tmp[i] -= 2;
59         if(Tmp[i] < 0) continue;
60
61         bool flag = 1;
62         For(j, 1, n+2) {
63             if(Tmp[j] < 0) {
64                 flag = 0;
65                 break;
66             }
67             if(!Tmp[j]) continue;
68             Tmp[j] %= 3;
69             Tmp[j+1] -= Tmp[j];
70             Tmp[j+2] -= Tmp[j];
71             Tmp[j] = 0;
72         }
73         if(flag)  return 1;
74     }
75     return 0;
76 }
77
78 inline void Solve() {
79     For(i, 1, n)
80         if(Check(i)) Ans[++Tot] = i;
81
82     if(!Tot) puts("NO");
83     else {
84         For(i, 1, Tot-1) printf("%d ", Ans[i]);
85         printf("%d\n", Ans[Tot]);
86     }
87 }
88
89 int main() {
90     #ifndef ONLINE_JUDGE
91     SetIO("1028");
92     #endif
93     Input();
94     Solve();
95     return 0;
96 }
View Code

//-------------------------------------------------------

dp[2][400][1000][1000][1000]

posted @ 2015-09-02 21:19  yanzx6  阅读(176)  评论(0编辑  收藏  举报