[计数DP] Happy Matt Friends 2014 北京ICPC

http://acm.hdu.edu.cn/showproblem.php?pid=5119

菜啊
计数DP没有看出来
没有看出来。。。。

H - Happy Matt Friends
HDU - 5119
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.
InputThe 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. OutputFor 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. Sample Input
2
3 2
1 2 3
3 3
1 2 3
Sample Output
Case #1: 4
Case #2: 2

Hint
In the first sample, Matt can win by selecting:
friend with number 1 and friend with number 2. The xor sum is 3.
friend with number 1 and friend with number 3. The xor sum is 2.
friend with number 2. The xor sum is 2.
friend with number 3. The xor sum is 3. Hence, the answer is 4.

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;

const int maxn = 1<<20;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;

// 计数dp 
// 1e6 20长度 2进制。。 
// 1024*1024 = 1e8+1e3; 
// 因为这个性质 a^b=c c^b=a;

// 所以 直接背包计数就可以了 dp[i][j] = dp[i - 1][j] + dp[i - 1][j ^ a[i]]



int t,n,m;
ll dp[3][1<<20];
int num[45];

int main(){
    scanf("%d",&t);
    int cas=1;
    while(t--){
        scanf("%d %d",&n,&m);
        for(int i=1;i<=n;i++) scanf("%d",&num[i]);
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=1;i<=n;i++){
            for(int j=0;j<maxn-5;j++){
                dp[i%2][j]=max(dp[(i)%2][j],dp[(i-1)%2][j^num[i]]+dp[(i-1)%2][j]);
            }
        }
        ll ans=0;
        for(int i=m;i<maxn-5;i++){
            ans+=dp[n%2][i];
        }
        printf("Case #%d: %lld\n",cas++,ans);
    }
    return 0;
} 
全部评论

相关推荐

💼公司岗位&nbsp;tx客户端岗本人背景中九硕,cpp选手。当时在牛子上看cpp选手找不到后端岗实习,遂投了腾子的客户端想练练手。🕐面试过程投递之后很快约面了,一面面试官比较和蔼问的也是正常八股加项目的模式。然后约了二面,二面面试官应该是入职后的leader,这轮面试就离谱了,一开始问了一些八股(感觉那面试官也不怎么懂技术像是照着书上写好的问题问一样),后面离谱的来了,直接疯狂压力测试(你为什么觉得你能xxx,你能不能接受xxx)。当时因为对tx还有滤镜,把自己当作一个牛马的姿态来回答这些问题。面完之后面试官可能觉得我是一个合格的牛马,他加了我微信,问我什么时候能去实习,我说六月初,他说有点晚了,然后考虑了一天还是给我过了面试,然后3面和hr面就也是正常流程了。🐶事件起因5月末的时候导师临时给安排了一个项目,于是我就去微信问那个leader,能不能推迟到6月24入职,如果不能我可以主动放弃offer,他当时犹豫再三还是同意了(现在回想起来可能是当时还没有备胎)。就在昨天他又问我什么时候入职,然后我说24号,他说有点晚叫我看看系统上还有没有其它入职时间,因为我还没在系统上填入职信息(在牛子上看到说只有快入职了,才会有人审核,遂想端午节后再填),查看不了可申请入职的时间。和他说了原因后,这下给他抓到把柄了,直接来一句&amp;quot;你对这次实习并不重视,确实没什么必要了&amp;quot;&nbsp;&nbsp;😅。感觉应该是找到备胎硬气了,就想把我踹走。不过爷也不想去了,客户端前景本来就不太好,这个leader也是个pua怪加压力怪,反正也是双向选择。最后再给大家一个建议,在面试过程中就感觉不舒服的组,一定不要去了,去了也只会更难受。 #不给转正的实习,你还去吗#&nbsp;&nbsp;#找实习多的是你不知道的事#
景洪:“在面试过程中就感觉不舒服的组,一定不要去了,去了也只会更难受。” 谢谢楼主的总结,这个太赞同了,我有次就是实习前面试感觉体验特别差,入职之后就是各种pua和压力。 大佬,你值得更好的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务