Skip to content

Commit 356a995

Browse files
committed
acwing: add 900_integer_partition.go
1 parent d14c6c5 commit 356a995

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
/*
8+
@Author: CodeWater
9+
@since: 2025/03/11
10+
@desc: 900. 整数划分
11+
按照完全背包思路来划分状态,f[i][j]前1到 i- 1个整数和是j的方案有多少个;优化成一维f[j]整数和是j。
12+
的有多少个。
13+
*/
14+
15+
const N, mod = 1010, 1e9 + 7
16+
17+
var (
18+
n int
19+
// f[j]:是整数j的划分数量
20+
f [N]int
21+
)
22+
23+
func main() {
24+
fmt.Scan(&n)
25+
26+
f[0] = 1
27+
for i := 1; i <= n; i++ {
28+
for j := i; j <= n; j++ {
29+
f[j] = (f[j] + f[j-i]) % mod
30+
}
31+
}
32+
33+
fmt.Println(f[n])
34+
}

0 commit comments

Comments
 (0)