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 + 注意数值大小相关推荐

  1. 【CodeForces - 768C】Jon Snow and his Favourite Number(思维,技巧,套路,数学异或,循环节,trick)

    题干: Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own streng ...

  2. codeforces 768 C. Jon Snow and his Favourite Number(思维+暴力)

    题目链接:http://codeforces.com/contest/768/problem/C 题意:给出n个数,k个操作,和一个x,每次操作先排序然后对奇数位数进行xor x操作,最后问k次操作后 ...

  3. Codeforces Round #265 (Div. 1) C. Substitutes in Number dp

    题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...

  4. JS Number类型的数值转换

    js有5种基本数据类型: undefined, Null, Boolean,Number, String(, Symbol).还有一种复杂类型数据: Object. Number() Number类型 ...

  5. 有趣题目和认知合集(持续更新)

    写写对一些算法的理解,挂几个有意思的题,可能也会挂几个板子题 算法理解偏向于能懂即可,没有严格的证明 快乐几何 [1.2]Volatile Kite 点到直线 快乐搜与暴力 [2.4]Short Co ...

  6. 命令执行顺序控制与管道

    1.顺序执行 yum install tools;yum install tools1;yum install tools2; 2.有选择的执行 which cowsay>/dev/null & ...

  7. Linux 命令详解

    1.帮助命令 1.1 help命令 #语法格式: 命令 --help #作用: 查看某个命令的帮助信息 # 示例: # ls --help 查看ls命令的帮助信息# netstat --help 查看 ...

  8. Linux文件内容排序命令sort

    sort 命令 sort将文件的每一行作为一个单位,相互比较, 比较原则是从首字符向后,依次按ASCII码值进行比较,最后将他们按升序输出. sort : 只有sort 情况下,前面有空格的默认排到最 ...

  9. LightOJ 1364 Expected Cards(概率+DP)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1364 题意:一副牌.依次在桌面上放牌.求放了四种花色的牌为C,D,H,S张时放的牌数的 ...

最新文章

  1. Nginx+FastCGI
  2. Git学习(一)git服务器的简易搭建
  3. spring3.x企业应用开发实战 pdf_吃透Spring全家桶:Spring源码+SpringBoot+SpringCloud实战...
  4. WOC?老板让我从Word中复制出1000张图片?
  5. TIMESTAMP和DATETIME哪个好
  6. MOCTF-Web-我想要钱
  7. mysql_result函数用不了_mysql_result()函数怎么在PHP中使用
  8. 一步步编写操作系统 50 加载内核3
  9. server sql 多表事物 自增id_最实用的 SQL 语句收藏,程序员看完这篇就够了!
  10. powershell_PowerShell图表功能概述
  11. [转]Thrift连接池实现
  12. URAL-1991 The battle near the swamp 水题
  13. js代码错误监控代码
  14. 设计模式(1)-- 七大软件设计原则-开闭原则
  15. Java编程练习题2
  16. Java代码实现SM2算法以及注意点总结(踩坑记录)
  17. 算法在计算机中的作用
  18. SpringBoot:yml文件详解
  19. Linux知识点总结(思维导图,建议收藏)
  20. System.BadImageFormatException: 试图加载格式不正确的程序。

热门文章

  1. HDU 4279 - Number
  2. Advapi 登录类型8的错误
  3. 10种顶级javascript框架比较-The Top 10 Javascript MVC Frameworks
  4. 区块链BAAS平台:公共或私人区块链编程以用于各种用途
  5. git常用命令及冲突解决
  6. 在线代码编辑器 Codemirror 的轻量级 React 组件
  7. 关于爬虫中常见的两个网页解析工具的分析 —— lxml / xpath 与 bs4 / BeautifulSoup...
  8. windows下实现自己的第一个python脚本文件并.exe运行
  9. 人民币数字金额转大写金额
  10. 通过VB向SQL Server数据库中录入数据