HDU 5119】的更多相关文章

题目链接:HDU 5119 Problem 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'ma…
http://acm.hdu.edu.cn/showproblem.php?pid=5119 题意:给出n个数和一个上限m,求从这n个数里取任意个数做异或运算,最后的结果不小于m有多少种取法. 思路:dp[i][j]表示在前i个数中取数做异或运算最后结果为j的方法数,那么dp[i][j] = dp[i-1][j] + dp[i-1][j^a[i]],分别对于取与不取这两种状态. 因为要推导出第i的状态只有i-1有关,所以这里可以用滚动数组. #include<cstdio> #include&…
被一个学长逼着做的题...谢谢他了~  题中dp[i][j] i即为第i个数,j为当前输入的数能xor到的数 同时一个数有两种选择,1.not xor  2.xor 最大的j不会超过11...11b(20个)=1048575   题目中用了1050000 #include <stdio.h> #include <string.h> #define MM 50 __int64 dp[MM][]; int num[MM]; int main() { int n,m,t,j,i; sca…
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others) Total Submission(s): 3215 Accepted Submission(s): 1261 Problem Description Matt has N friends. They are playing a game together. Each of Matt's frie…
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 , Mat…
题意:给定n个数,从中分别取出0个,1个,2个...n个,并把他们异或起来,求大于m个总的取法. 思路:dp,背包思想,考虑第i个数,取或者不取,dp[i][j]表示在第i个数时,异或值为j的所有取法.dp[i][j] = dp[i - 1][j] + dp[i - 1][j ^ a[i]]); 其中dp[i - 1][j]表示不取第i个数,dp[i - 1][j ^ a[i]]表示取第i个数,由于40比较大,所以用滚动数组优化,后一个状态需要前一个来推导,而和前一个之前的所有的没有关系,所以之…
虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[i]] + dp[i - 1][j]; dp[i][j] 的意思是,对于数列 中前 i 个数字,使得 XOR 和恰好为 j 的方案数 状态转移方程中的 dp[i - 1][j] 即表示当前这个数字不取, dp[i - 1][j ^ a[i]] 表示当前这个数字要取. 这道题还是要好好理解阿! sou…
题意: 随机选择一个数,如果后面有比他小的就进行交换,直到没有为止(算一轮).求多少轮后为递增序列 思路: 倒着找,如果有比经过的最小数大的,ans+1 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int a[1000005]; int main() { int T,n; scanf("%d&qu…
题目链接 题意:n个数,你可以从中选一些数,也可以不选,选出来的元素的异或和大于m时,则称满足情况.问满足情况的方案数为多少. 分析:本来以为是用什么特殊的数据结构来操作,没想到是dp,还好队友很强.定义dp[i][j]为在前i个数里选一些数的异或和为j的方案数,边计算边统计, #include <iostream> #include <cstdio> #include <cstring> typedef long long ll; <<); using n…
题目链接 题意 : 给你n个数,让你从中挑K个数(K<=n)使得这k个数异或的和小于m,问你有多少种异或方式满足这个条件. 思路 : 正解据说是高斯消元.这里用DP做的,类似于背包,枚举的是异或的和,给定的数你可以选择放或者不放,dp[i][j]代表的是前 i 个数中选择k个异或的和为j. #include <stdio.h> #include <string.h> #include <iostream> #define LL long long using na…