标签:res hid str problems sort long cto type space
acmsguru 552 - Database Optimization
充分利用STL即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+7; 5 const ll mod = 998244353; 6 const int sz = 25; 7 #define afdafafafdafaf y1; 8 int n,m; 9 int ar[maxn]; 10 map<string, int> mp; 11 int ins=0; 12 map<vector<int>, int> ms; 13 int decode(string s){ 14 if(mp.count(s) == 0){ 15 mp[s] = ins++; 16 } 17 return mp[s]; 18 } 19 vector<int> res, in; 20 void dfs(int x){ 21 if(x==in.size()){ 22 if(res.size() == 0)return ; 23 vector<int> mid = res; 24 sort(res.begin(), res.end()); 25 ms[res]++; 26 res = mid; 27 } 28 else{ 29 dfs(x+1); 30 res.push_back(in[x]); 31 dfs(x+1); 32 res.pop_back(); 33 } 34 } 35 char ch[maxn]; 36 int main() 37 { 38 scanf("%d", &n); 39 for(int i=1; i<=n; i++){ 40 int k;scanf("%d", &k); 41 in.resize(0); 42 while(k--){ 43 scanf("%s", ch); 44 in.push_back(decode(string(ch))); 45 } 46 dfs(0); 47 assert(res.size() == 0); 48 } 49 scanf("%d", &m); 50 for(int i=1; i<=m; i++){ 51 int k;scanf("%d", &k); 52 in.resize(0); 53 while(k--){ 54 scanf("%s", ch); 55 in.push_back(decode(string(ch))); 56 } 57 sort(in.begin(), in.end()); 58 printf("%d\n", ms[in]); 59 } 60 return 0; 61 }
标签:res hid str problems sort long cto type space
原文地址:https://www.cnblogs.com/wa007/p/11620826.html