博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hustwinterC - Happy Matt Friends(dp解法)
阅读量:4626 次
发布时间:2019-06-09

本文共 1821 字,大约阅读时间需要 6 分钟。

Description

Matt has N friends. They are playing a game together. 
Each of Matt’s friends has a magic number. In the game, Matt selects some (could be zero) of his friends. If the xor (exclusive-or) sum of the selected friends’magic numbers is no less than M , Matt wins. 
Matt wants to know the number of ways to win.
 

Input

The first line contains only one integer T , which indicates the number of test cases. 
For each test case, the first line contains two integers N, M (1 ≤ N ≤ 40, 0 ≤ M ≤ 10 6). 
In the second line, there are N integers ki (0 ≤ k i ≤ 10 6), indicating the i-th friend’s magic number.
 

Output

For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y indicates the number of ways where Matt can win.
 

  正解貌似是高斯消元....不会的说....PYY说不就是解方程么....然后我去看了下.....挺多概念没学线代的话还是挺眼生的...(orzpyy大神)记得高三的时候做过一个用矩阵加速求线性递推式的东西....当时10^18的数据秒过....还是挺让我惊讶了一下...

扯远了... 这题dp也能做,有点类似01背包(dp真是够渣,寒假看看能不能抽时间弄一下,依然是最大的短板)
只不过状态转移方程是 dp[i][j]=dp[i-1][j]+dp[i-1][j^a[i]]
然后正常些貌似会MLE。。。。。用到了滚动数组
其实滚动数组,完全...没有理解的难度啊 
竟然是我第一次使用,大概是因为基本没怎么做过DP的题吧,而滚动数组这个优化貌似主要在Dp的题里需要...
然后在搜滚动数组的时候,看到一篇博客里用异或来表示两个状态我觉得这一点也很赞.....
我自己想的话的大概就要又加,又mod,然后还得再来一个变量了吧.....差评满满
还有位运算....是挺神的东西....目前还处于一知半解的阶段....ORZ  M67大神
 

1   2 #include
3 #include
4 #include
5 #include
6 const long long C=1<<21; 7 long long dp[2][C]; 8 using namespace std; 9 10 int main()11 {12 int t,a[49];13 cin>>t;14 int tt;15 tt=t;16 while (t--)17 18 {19 int n,m,roll;20 roll=0;21 memset(dp,0,sizeof(dp));22 dp[0][0]=1;23 cin>>n>>m;24 for(int i=0;i
>a[i];26 27 for(int i=0;i

 

 
 

转载于:https://www.cnblogs.com/111qqz/p/4295354.html

你可能感兴趣的文章
MySql数据库的下载和安装卸载
查看>>
JDBC接口核心的API
查看>>
用Python编写WordCount程序任务
查看>>
AC日记——传纸条 洛谷 P1006
查看>>
React显示文件夹中SVG
查看>>
微引擎的自定义菜单40063错误解决
查看>>
JAVA wait(), notify(),sleep具体解释
查看>>
数据挖掘十大经典算法
查看>>
WebService原理
查看>>
【Unity 3D】学习笔记三十七:物理引擎——碰撞与休眠
查看>>
计算机网络中的TCP/IP模型
查看>>
spring mvc 自定义Handlermapping
查看>>
JS验证密码安全级别
查看>>
Cookie是可以覆盖的,如果重复写入同名的Cookie,那么将会覆盖之前的Cookie。
查看>>
高并发 Nginx+Lua OpenResty系列(11)——流量复制/AB测试/协程
查看>>
高并发 Nginx+Lua OpenResty系列(8)——Lua模版渲染
查看>>
跟我学SpringCloud | 第三篇:服务的提供与Feign调用
查看>>
高并发 Nginx+Lua OpenResty系列(9)——HTTP服务
查看>>
跟我学SpringCloud | 第五篇:熔断监控Hystrix Dashboard和Turbine
查看>>
高并发 Nginx+Lua OpenResty系列(10)——商品详情页
查看>>