首页 > 其他分享 >ABC 248 C - Dice Sum(DP:背包)

ABC 248 C - Dice Sum(DP:背包)

时间:2022-10-04 11:00:54浏览次数:83  
标签:ABC const Dice Sum cin Sample LL 数字

https://atcoder.jp/contests/abc248/tasks/abc248_c

题目大意:

给定长度为n,可选择的数字的范围【1,m】,放置的数字的总和不能超过k;

问我们能凑出多少种不同的情况?取模。
Sample Input 1
2 3 4
Sample Output 1 
6

Sample Input 2 
31 41 592
Sample Output 2
798416518
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=200200,M=2522;
const LL mod=998244353;
LL f[100][M];
//f[i][j]表示前i个数字,总数为j
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n,m,k;//长度,范围,最大总和
        cin>>n>>m>>k;
        
        LL res=0;
        f[0][0]=1;//长度为0,总和为0的时候,只有一种情况
        
        for(LL i=1;i<=n;i++)//长度
        {
            for(LL j=0;j<=k;j++)//可以凑出的总和
            {
                for(LL last=1;last<=m;last++)//区间选择
                {
                    //如果当前选择的数字都会比总和更小的话,那么我们就一定可以前面由一些数字给他凑出来(即使为0)
                    //位数减去一,并且总数减去这一个last那么就可以拼凑出现在的总和

                    //如果我要凑出的总和大于这个数字的话,那么我们就可以往前寻找可以凑出来的可能性
                    if(j>=last) f[i][j]=(f[i][j]+f[i-1][j-last])%mod;//可以添加这位数字
                }
            }
        }
        for(LL j=0;j<=k;j++)//把相同的长度下,总和为不同的数字的情况都加起来
            res=(res+f[n][j])%mod;
        cout<<res<<endl;
    }
    return 0;
}

标签:ABC,const,Dice,Sum,cin,Sample,LL,数字
From: https://www.cnblogs.com/Vivian-0918/p/16753416.html

相关文章

  • mybatisplus不支持sum,但支持这个
    我们知道,要对数据求和,写sql很简单:selectsum(exp)fromtable_name我们在用mybatisplus做求和计算的时候,mybatisplus的Wrapper不支持sum函数。这种情况下,我们就无法使用lamb......
  • ABC 246 D - 2-variable Function(数论/暴力)
    https://atcoder.jp/contests/abc246/tasks/abc246_d题目大意:给定一个数字N,让我们求出X,这个X要满足X>=N,并且X内部可以有一对(a,b)满足a^3+a^2*b+b^2*a+b^3。找出最......
  • ABC 246 C - Coupon(思维)
    怎么最近连纯思维题都写不出来了???我人傻了https://atcoder.jp/contests/abc246/tasks/abc246_c题目大意:给定n个价钱,我们手里有k个优惠卷,每个优惠卷都可以减7元;假如......
  • LeetCode 363. Max Sum of Rectangle No Larger Than K
    原题链接在这里:https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/题目:Givenan mxn matrix matrix andaninteger k,return themaxsum......
  • ABC-270 F - Transportation(kruskal)
    ABC-270F-Transportation(kruskal)考虑等价转换,建立两个虚点(分别表示airport和harbor的中转站)。这样就可以把点统一为边权问题。对于操作1和操作2,就是等价于向虚点连边......
  • solution-arc149(ABC)
    A就是枚举,先枚举是哪个数再枚举位数。把这种题放arcA感觉挺没意思。#include<cstdio>usingnamespacestd;intansx,ansy;voidcheckmax(inti,intj){if(......
  • AWS SAA summary-Exam 02
    4EC24.1EC2conceptAmazonElasticComputeCloud(AmazonEC2)是一种Web服务,在云中提供大小可调的计算容量。该服务旨在让开发人员能更轻松地进行Web级的计算。All......
  • L10U1-4-Summarizing-a-meeting
    1VocabularyIssues,decisionsandchangesWatchthevideoandstudythelanguage.JOAN:Okay,soDavidmetwiththeboardofdirectorsthismorning.They'vedeci......
  • Summary of Latex
    关系符$\le$ :\le\(\ge\):\ge\(\neq\):\neq希腊字母\(\alpha\):\alpha\(\beta\):\beta\(\phi\):\phi其他换行符:\\空格符:\quad......
  • Summary of Classic Cryptography
    Easybutessential.整理出来方便自己做题的时候查看。单表替换Caesar:原理:凯撒密码(Caesar)加密时会将明文中的每个字母都按照其在字母表中的顺序向后(或向前)移动固定......