fork(1) download
  1. #include <set>
  2. #include <map>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iomanip>
  14. #include <complex>
  15. #include <iostream>
  16. #include <algorithm>
  17.  
  18. #include <ctime>
  19. #include <deque>
  20. #include <bitset>
  21. #include <cctype>
  22. #include <utility>
  23. #include <cassert>
  24. using namespace std;
  25.  
  26. #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
  27. #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
  28. #define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
  29. #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
  30.  
  31. #define DEBUG(x) { cout << #x << " = " << x << endl; }
  32. #define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
  33. #define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
  34.  
  35. int a[8011];
  36. long long f[11][66];
  37.  
  38. int main() {
  39. ios :: sync_with_stdio(false); cin.tie(NULL);
  40. cout << (fixed) << setprecision(6);
  41. int test; cin >> test;
  42. while (test--) {
  43. int m, n, q; cin >> m >> n >> q;
  44. FOR(i,1,m) {
  45. string s; cin >> s;
  46. a[i] = s.length();
  47. }
  48.  
  49. memset(f, 0, sizeof f);
  50. f[0][0] = 1;
  51. FOR(i,0,n-1)
  52. FOR(l,0,50)
  53. if (f[i][l] >= 0) {
  54. FOR(add,1,m)
  55. f[i+1][l + a[add]] += f[i][l];
  56. }
  57.  
  58. while (q--) {
  59. int x; cin >> x;
  60. cout << f[n][x] << endl;
  61. }
  62. }
  63. return 0;
  64. }
  65.  
  66.  
Success #stdin #stdout 0s 3512KB
stdin
1
4 2 2
aap
noot
mies
piet
7
8
stdout
6
9