File tree 2 files changed +74
-0
lines changed
2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ . "fmt"
5
+ "io"
6
+ )
7
+
8
+ // 另一种效率更高的做法是折半枚举,见 https://codeforces.com/blog/entry/8274
9
+
10
+ // github.com/EndlessCheng/codeforces-go
11
+ func CF327E (in io.Reader , out io.Writer ) {
12
+ const mod int = 1e9 + 7
13
+ var n , k int
14
+ Fscan (in , & n )
15
+ m := 1 << n
16
+ sum := make ([]int , m )
17
+ for i := 0 ; i < n ; i ++ {
18
+ Fscan (in , & sum [1 << i ])
19
+ }
20
+ b := [2 ]int {}
21
+ Fscan (in , & k , & b [0 ], & b [1 ])
22
+ f := make ([]int , m )
23
+ f [0 ] = 1
24
+ for s := 1 ; s < m ; s ++ {
25
+ lb := s & - s
26
+ v := sum [s ^ lb ] + sum [lb ]
27
+ if v > 1e9 + 1 {
28
+ v = 1e9 + 1
29
+ }
30
+ sum [s ] = v
31
+ if v != b [0 ] && v != b [1 ] {
32
+ dv := 0
33
+ for sub , lb := s , 0 ; sub > 0 ; sub ^= lb {
34
+ lb = sub & - sub
35
+ dv += f [s ^ lb ]
36
+ if dv >= mod {
37
+ dv -= mod
38
+ }
39
+ }
40
+ f [s ] = dv
41
+ }
42
+ }
43
+ Fprint (out , f [1 << n - 1 ])
44
+ }
45
+
46
+ //func main() { CF327E(os.Stdin, os.Stdout) }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "github.com/EndlessCheng/codeforces-go/main/testutil"
5
+ "testing"
6
+ )
7
+
8
+ // https://codeforces.com/problemset/problem/327/E
9
+ // https://codeforces.com/problemset/status/327/problem/E
10
+ func TestCF327E (t * testing.T ) {
11
+ // just copy from website
12
+ rawText := `
13
+ inputCopy
14
+ 3
15
+ 2 3 5
16
+ 2
17
+ 5 7
18
+ outputCopy
19
+ 1
20
+ inputCopy
21
+ 3
22
+ 2 2 2
23
+ 2
24
+ 1 3
25
+ outputCopy
26
+ 6`
27
+ testutil .AssertEqualCase (t , rawText , 0 , CF327E )
28
+ }
You can’t perform that action at this time.
0 commit comments