hdu 6425 Rikka with Badminton


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 231    Accepted Submission(s): 147

Problem Description

In the last semester, Rikka joined the badminton club.
There are n students in the badminton club, some of them have rackets, and some of them have balls. Formally, there are a students have neither rackets nor balls, bstudents have only rackets, c students have only balls, and d students have both rackets and balls. (a+b+c+d=n)
This week, the club is going to organize students to play badminton. Each student can choose to take part in or not freely. So there are 2n possible registration status. 
To play badminton, there must be at least two students who have rackets and at least one students who have balls. So if there aren't enough balls or rackets, the activity will fail. 
Now, Rikka wants to calculate the number of the status among all 2n possible registration status which will make the activity fail.

Input

The first line contains a single number t(1≤t≤103), the number of testcases.
For each testcase, the first line contains four integers a,b,c,d(0≤a,b,c,d≤107,a+b+c+d≥1).

Output

For each testcase, output a single line with a single integer, the answer modulo 998244353.

Sample Input

3

1 1 1 1

2 2 2 2

3 4 5 6

Sample Output

12

84

2904

题目意思:一个羽毛球俱乐部里面有n个人,周末他们组织活动(当然是打羽毛球啦),每个人可以选择去还是不去,那么将会出现2^n种结果。这n个人里面有a个人既没有球也没有球拍,b个人有一只球拍,c个人有一个球,d个人既有球又有一只球拍。能打羽毛球就必须有2个球拍和1个球。问你这2^n种情况里面有多少种情况是不能打羽毛球的。

题解 : 我们可以分情况来取

1.什么都不取的话只有1种。

2.只取一类人的情况 : a、b、c无论怎么取都可以满足提议,而d最多只能取一个,所以不可以的方案数为 :(2^a-1) + (2^b-1) + (2^d-1) + 1; 减1是去掉什么都不取的情况。

如果同时取两类人,对于a,b和a,c来说,怎么取都无所谓,a,d的话d只能取一人,b,c也是b只能取一人,c,d也是d只能取一人,所以就是

(2^{a}-1)*(2^{b}-1)+(2^{a}-1)*(2^{c}-1)+(2^{a}-1)*C_{d}^{1}\textrm{}+(2^{c}-1)*C_{b}^{1}\textrm{}+(2^{c}-1)*C_{d}^{1}\textrm{}
如果同时取三类人,对于a,b,c和a,c,d来说,b和d只能取一个,而b,c,d不可取,所以就是]

(2^{a}-1)*(2^{c}-1)*C_{b}^{1}\textrm{}+(2^{a}-1)*(2^{c}-1)*C_{d}^{1}\textrm{}

四类人都存在的情况不符和题意。

贴代码:

#include<bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long quick(long long a,long long times){
	long long ans = 1;
	while(times){
		if(times & 1){
			ans = (ans * a) % mod;
		}
		a = (a * a) % mod;
		times /= 2;
	}
	return ans;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		long long a,b,c,d;
		scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
		long long ans = 0;
		long long powa = quick(2,a) - 1;
		long long powb = quick(2,b) - 1;
		long long powc = quick(2,c) - 1;
		ans = (1 + powa + powb + powc + d + (powa * powb) % mod + (powa * powc) % mod + (powa * d) % mod + (powc * d) % mod + (powc * b) % mod + ((powa * powc) % mod * b) % mod + ((powa * powc) % mod * d) % mod) % mod;
		printf("%lld\n",ans);
	}	 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值