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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

C. Jon Snow and his Favourite Number DP + 注意数值大小

發布時間:2023/12/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C. Jon Snow and his Favourite Number DP + 注意数值大小 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://codeforces.com/contest/768/problem/C

這題的數值大小只有1000,那么可以聯想到,用數值做數組的下標,就是類似于計數排序那樣子。。

這樣就可以枚舉k次操作,然后for (int i = 0; i <= 1025; ++i),也就是O(1000 * k)的復雜度而已。

0--1000中任選兩個數異或,最大值是1023

然后注意下只有奇數位異或,dp[now][val]計數轉移下去就好了

#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL;#include <iostream> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <string> #include <bitset> const int maxn = 1e5 + 20; int a[maxn]; vector<int>vc[maxn]; map<pair<int, int>, int>pos; int dp[2][1025 + 20]; int f(int val) {return (val + 1) / 2; } void work() {int n, k, x;cin >> n >> k >> x;for (int i = 1; i <= n; ++i) {cin >> a[i];dp[0][a[i]]++;}int now = 0;for (int i = 1; i <= k; ++i) {now = !now;memset(dp[now], 0, sizeof dp[now]);int L = 1, R = 0;for (int j = 0; j <= 1025; ++j) {if (dp[!now][j]) {R = L + dp[!now][j] - 1;int has = f(R) - f(L - 1);dp[now][j ^ x] += has;dp[now][j] += dp[!now][j] - has;L = R + 1;}}assert(L == n + 1);}int mi = inf, mx = -inf;for (int i = 0; i <= 1025; ++i) {if (dp[now][i]) {mi = min(i, mi);mx = max(i, mx);}}cout << mx << " " << mi << endl; }int main() { #ifdef localfreopen("data.txt", "r", stdin); // freopen("data.txt", "w", stdout); #endifwork();return 0; } View Code

?

轉載于:https://www.cnblogs.com/liuweimingcprogram/p/6426291.html

總結

以上是生活随笔為你收集整理的C. Jon Snow and his Favourite Number DP + 注意数值大小的全部內容,希望文章能夠幫你解決所遇到的問題。

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