HDU6425 Rikka with Badminton (容斥原理)

Description:

In the last semester, Rikka joined the badminton club. 

There are nn students in the badminton club, some of them have rackets, and some of them have balls. Formally, there are aa students have neither rackets nor balls, bb students have only rackets, cc students have only balls, and ddstudents have both rackets and balls. (a+b+c+d=n)(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 2n2n 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 2n2n possible registration status which will make the activity fail.

Input

The first line contains a single number t(1≤t≤103)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)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 998244353998244353.

Sample Input

3
1 1 1 1
2 2 2 2
3 4 5 6

Sample Output

12
84
2904

一群人打羽毛球,a个人啥都没有,b个人只有一个拍,c个人只有一个球,d个人有一个拍一个球,只有同时有两个拍一个球才能一起打,问多少种情况不能一起打

有三种情况不能一起打,

1.没有球,

2.没有拍,

3.只有一个拍

A:无拍  2^a*2^a;

B:只有一个拍: 2^a*2^c*b+2^a*2^c*d

C:无球:   2^a*2^b

AB:相互矛盾  0

AC:无拍无球 2^a

BC: 一个拍无球 2^a*b

方法总数:A+B+C-AB-AC-BC

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<iomanip>
#include<math.h>
const int INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
typedef double ld;
const int N=1e6+10;
const int MOD=998244353;
ll a,b,c,d;

ll mi(ll x,ll y)
{
    if(!y)
        return 1;
    ll temp=mi(x,y/2);
    temp*=temp;
    temp%=MOD;
    if(y&1)
        {
        temp*=x;
        temp%=MOD;
    }
    return temp;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
        {
        scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
        ll ans=mi(2,a+c);
        ans=((b+d+1)*ans)%MOD;
        ans=(ans+mi(2,a+b));
        ans=(ans-(mi(2,a)*(b+1))%MOD)%MOD;
        ans=(ans+MOD)%MOD;
        printf("%lld\n",ans);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值