标签:sicily
Time Limit: 1 secs, Memory Limit: 256 MB
Given two words A and B, a word W is said to be good if it satisfies the following conditions simultaneously.
1) All letters in W are also in A.
2) No letter in W is in B.
3) W contains N letters.
Given N, A and B, your task is to find out how many different good words exist.
The input begins with a line containing an integer T (T<=50), which indicates the number of test cases. The following T lines each contain an integer N (1<=N<=10000), and two words A and B. A and B only contain lowercase English letters. The length of each word will not exceed 50.
For each case, output the number of different good words in a line. The answer may be very large, so just output the remainder of the answer after divided by 1007.
3 3 lby myf 1 ddfg ffgd 5 lby ygl
8 0 1
For the first test case, you can generate 8 good words: lll, llb, lbl, lbb, bll, blb, bbl, bbb.
SYSUCPC 2014 Preliminary (Online) Round
#include <iostream>
#include <string>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int caseNum;
cin >> caseNum;
while (caseNum--) {
int n, m = 0, ans = 1;
string a, b;
cin >> n >> a >> b;
bool isOK['z' + 1];
for (int i = 'a'; i <= 'z'; i++) isOK[i] = false;
for (int i = a.size() - 1; i >= 0; i--) isOK[a[i]] = true;
for (int i = b.size() - 1; i >= 0; i--) isOK[b[i]] = false;
for (int i = 'a'; i <= 'z'; i++) if (isOK[i]) m++;
for (int i = 0; i < n; i++, ans %= 1007) ans *= m;
cout << ans << endl;
}
return 0;
}Sicily 14261. Generating Words
标签:sicily
原文地址:http://blog.csdn.net/u012925008/article/details/44929431