0%

[題解]巧克力擺盒

a135. 巧克力擺盒

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define Orz ios::sync_with_stdio(0),cin.tie(0)
#define N 51
#define FOR(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pid pair<int,double>
#define pdi pair<double,int>
using namespace std;
int n,m,k;
int r[9],box[9];;

bool cmp(vector<int> r){
for(int i=0;i<9;i+=3){
if(r.size()==3){
if((r[0]&box[i])&&(r[1]&box[i+1])&&(r[2]&box[i+2])){
return true;
}
//對於這一行的指定是有滿足的,回傳正確(下一個要求繼續再呼叫一次)
}
else if(((r[0]&box[i])&&(r[1]&box[i+1]))||((r[0]&box[i+1])&&(r[1]&box[i+2]))){
return true;
}
}
return false;
}

vector<int> rule;
vector<vector<int>> rule_list;

void solve(){
for(int i=0;i<9;i++){
int temp=1;temp = temp<<i;
r[i] = temp;
box[i] = temp;
}
map<string,int> mp = {
{"PS",r[0]},
{"PC",r[1]},
{"PT",r[2]},
{"P?",r[0]|r[1]|r[2]},
{"BS",r[3]},
{"BC",r[4]},
{"BT",r[5]},
{"B?",r[3]|r[4]|r[5]},
{"YS",r[6]},
{"YC",r[7]},
{"YT",r[8]},
{"Y?",r[6]|r[7]|r[8]},
{"?S",r[0]|r[3]|r[6]},
{"?C",r[1]|r[4]|r[7]},
{"?T",r[2]|r[5]|r[8]},
{"??",511},
};
cin>>n;
while(n--){
cin>>k;
rule.resize(k);
for(int i=0;i<k;i++){
char temp[3];cin>>temp[0]>>temp[1];
rule[i] = (mp[temp]);
}
rule_list.push_back(rule);
}
int ans = 0;
do{
ans += all_of(rule_list.begin(),rule_list.end(),cmp);

}while(next_permutation(box,box+9));

cout<<ans<<endl;
}

signed main(){
Orz;
int t=1;
while(t--){
solve();
}
}