链接 :I-小莫的计数(简单版本)_2023新疆大学新生赛 (nowcoder.com)
困难版本不会写就不放出来了
题意:给你m个约束,b前字符不能是a,长度为n的字符串有多少种不同方式
set里存约束关系,两个for遍历找满足的条件
void solve() { mp['M'] = 0; mp['O'] = 1; mp['N'] = 2; mp['I'] = 3; mp['K'] = 4; mp['A'] = 5; set<int> st[10]; int n,m; cin >> n >> m; for(int i = 1; i <= m ; i ++) { char c, ch; cin >> c >> ch; st[mp[ch]].insert(mp[c]); //cout << mp[ch] << ' ' << mp[c] << endl; } memset(dp, 0, sizeof dp); for(int i = 0; i <= 5; i ++) dp[1][i] = 1; for(int i = 2; i <= n; i ++) { for(int j = 0; j <= 5; j ++)//当前字符 { for(int k = 0; k <= 5; k ++)//前一个 { if(st[j].find(k) != st[j].end()) continue; dp[i][j] = (dp[i][j] += dp[i - 1][k]) % mod; } } } int res = 0; for(int i = 0; i <= 5; i ++) res = (res + dp[n][i]) % mod; //for(int i = 0; i <= 5; i ++) cout << dp[n][i] << endl; cout << res << endl; }
标签:set,小莫,int,计数,mp,版本 From: https://www.cnblogs.com/ZouYua/p/17790566.html