File tree Expand file tree Collapse file tree 1 file changed +89
-0
lines changed
Expand file tree Collapse file tree 1 file changed +89
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.util.* ;
4+ import java.io.* ;
5+
6+
7+ class Solution {
8+
9+ // IO field
10+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
12+ static StringTokenizer st;
13+
14+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
15+ static int nextInt() {return Integer . parseInt(st. nextToken());}
16+ static long nextLong() {return Long . parseLong(st. nextToken());}
17+ static void bwEnd() throws Exception {bw. flush();bw. close();}
18+
19+ // Additional field
20+ static int [] A ;
21+ static int [] dp;
22+ static int N ;
23+ static final int mod = (int )1e9 + 7 ;
24+
25+ public static void main(String [] args) throws Exception {
26+
27+ int TC ;
28+ TC = Integer . parseInt(br. readLine());
29+ ready(TC );
30+
31+ bwEnd();
32+
33+ }
34+
35+ static void ready(int TC ) throws Exception {
36+
37+ for (int tc= 1 ;tc<= TC ;tc++ ) {
38+
39+ // Write Code
40+
41+ char [] temp = br. readLine(). toCharArray();
42+ N = temp. length;
43+ A = new int [N + 1 ];
44+ for (int i= 1 ;i<= N ;i++ ) A [i] = temp[i- 1 ]- ' A' ;
45+ dp = new int [16 ];
46+
47+ //
48+
49+ solve(tc);
50+
51+ }
52+
53+ }
54+
55+ static void solve(int tc) throws Exception {
56+
57+ // Solve part
58+ for (int x= 0 ;x< 16 ;x++ ) if ((x& 1 ) != 0 && (x& (1 << A [1 ])) != 0 ) dp[x] = 1 ;
59+ for (int i= 2 ;i<= N ;i++ ) {
60+ int [] ndp = new int [16 ];
61+ for (int x= 0 ;x< 16 ;x++ ) if ((x& (1 << A [i])) != 0 ) {
62+ for (int y= 0 ;y< 16 ;y++ ) if ((x & y) != 0 ) {
63+ ndp[x] += dp[y];
64+ ndp[x] %= mod;
65+ }
66+ }
67+ dp = ndp;
68+ }
69+
70+ int ans = 0 ;
71+ for (int i= 0 ;i< 16 ;i++ ) ans = (ans + dp[i]) % mod;
72+
73+ //
74+
75+ bw. write(" #" + tc + " " );
76+
77+ // Output part
78+
79+ bw. write(ans + " \n " );
80+
81+ //
82+
83+ }
84+
85+
86+
87+ }
88+
89+ ```
You can’t perform that action at this time.
0 commit comments