【快速幂+组合】hdu 2018 多校第九场 1011 Rikka with Badminton hdu6425

Rikka with Badminton

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

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

给你a,b,c,d四种人的人数:分别代表什么都没有,一个拍,一个球,一个球一个拍

问你有多少种可能连一个球两个拍都没有

首先不管d:只有拍是2^a*2^b

                    可能有球和拍:2^a*2^c*(1+b)

                    减去重复的地方:没拍的时候是2^a

有d的话只能有一个d:2*a*2^c*d

加上第一三四条减去第二条就可以了

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
//ll p[4e7+4];

ll quickpow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll ans=quickpow(2,a)*quickpow(2,b)%mod;
        ans=(ans+((quickpow(2,a+c)-quickpow(2,a)+mod)%mod*(1+b))%mod)%mod;
        ans=(ans+(quickpow(2,a+c)*d%mod))%mod;
        printf("%lld\n",ans);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值