HDU 6425-Rikka with Badminton(DP/组合数)

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, b students 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

题目大意:想打羽毛球有4种人,什么都没有的人,有一个球拍的人,有一个球的人,有一个球拍+一个球的人。给出四种人的数量,随意组合,若组合至少有2个球拍和1个球,则该组合是可以愉快的玩耍的。现在输出不能愉快玩耍的组合数。

思路:考虑组合的大致类型,abcd分别为4种人,则可玩耍的只有四种组合:abcd、bcd、bd、abd。剩余的则为不可成功的组合,那么可选择总数减去成功数或直接求不成功的种数。

考虑直接求:a类一无所有,所以可以和所有类组合,即为2^a;d类只能与c或a组合,则为d*(2^c+2^a);b类可与a或c组合,则为(2^b+b^(2^c-1))*2^a;c类可与b或a组合,则为(2^c-1)*2^a;

即总的为(d*2^c+(b+1)*(2^c-1)+2^b)*2^a;

第二种解法:DP,吉老师的标解,因为只需要有1对拍和一个球就满足条件,所以标记当前的状态即可。

组合数代码:

#include<set>
#include<map>
#include<list>
#include<deque>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ext/rope>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define per(i,a,b) for(int i=a;i<=b;++i)
#define max(a,b)  a>b?a:b
#define min(a,b)  a<b?a:b
#define LL long long 
//#define swap(a,b) {int t=a;a=b;b=t} 
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
ll mod= 998244353;
ll pow(ll x,ll n,ll mod)
{
    ll res=1;
    while(n>0)
    {
       if(n%2==1)    
       {
            res=res*x;
            res=res%mod;
       }
       x=x*x;
       x=x%mod;
       n>>=1;
    }
    return res;    
}
int main()
{
    long long int a,b,c,d,i,j,t;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        long long int s=pow(2,a,mod)*((d%mod*pow(2,c,mod))%mod+((b+1)%mod*(pow(2,c,mod)-1))%mod+pow(2,b,mod))%mod;
        printf("%lld\n",s);
    }
    return 0;
}

DP标程如下:

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值