2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) - D Count The Bits
生活随笔
收集整理的這篇文章主要介紹了
2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) - D Count The Bits
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接
Given an integer k and a number of bits b (1 ≤ b ≤ 128), calculate the total number of 1 bits in thebinary representations of multiples of k between 0 and 2b{2^b}2b? 1 (inclusive), modulo 1,000,000,009.
Input
The input will consist of two integers k and b on a single line, with 1 ≤ k ≤ 1000 and 1≤ b ≤ 128.
Output
Write your result as an integer on a single line.
題意
求0~2b{2^b}2b中所有k的倍數二進制表示1的個數
思路
數位dp:
- dp[ i ][ j ] 表示到第i個二進制(0~(21?1){(2^1-1)}(21?1)),中模K余數為j的二進制表示1的個數
- cnt[ i ][ j ] 表示到第i個二進制(0~(21?1){(2^1-1)}(21?1)),中模K余數為j的數的個數
狀態轉移:
j = (2i+pre)%K{(2^i + pre) \% K}(2i+pre)%K
- dp[ i ][ j ] = dp[ i - 1 ][ j ] + dp[ i - 1 ][ pre ] + cnt[ i - 1 ][ pre ]
- cnt[ i ][ j ] = cnt[ i - 1 ][ j ] + cnt[ i - 1 ][ pre ]
Ans = dp[ n ][ 0 ]
總結
以上是生活随笔為你收集整理的2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) - D Count The Bits的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二分图匹配问题
- 下一篇: hihoCoder #1449 : 后缀