日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) - D Count The Bits

發布時間:2024/4/18 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 ]
#include <bits/stdc++.h> #define LL long long #define P pair<int, int> #define lowbit(x) (x & -x) #define mem(a, b) memset(a, b, sizeof(a)) #define rep(i, a, n) for (int i = a; i <= n; ++i) #define maxn 1005 #define mid ((l + r) >> 1) #define lc rt<<1 #define rc rt<<1|1 using namespace std; // __int128 read() { __int128 x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f;} // void print(__int128 x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) print(x / 10); putchar(x % 10 + '0');} // p1 not equal, p2 equal int inf = 0x3f3f3f3f; const LL mod = 1e9 + 9; LL dp[200][1003], cnt[200][1003];int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endifios::sync_with_stdio(false);cin.tie(0); cout.tie(0);LL k, b;while (cin >> k >> b) {mem(cnt, 0);mem(dp, 0);cnt[1][0]++;cnt[1][1%k]++;dp[1][1%k]++;LL tmp = 1 % k;for (int i = 2; i <= b; ++i) {tmp = tmp * 2 % k;for (int j = 0; j < k; ++j) {int pre = (j + k - tmp) % k;cnt[i][j] = (cnt[i-1][j] + cnt[i-1][pre]) % mod;dp[i][j] = (dp[i-1][j] + cnt[i-1][pre] + dp[i-1][pre] % mod) % mod;}}cout << dp[b][0] << endl;}return 0; }

總結

以上是生活随笔為你收集整理的2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) - D Count The Bits的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。