AtCoder Beginner Contest 220 D - FG operation

在这里插入图片描述
ABC几乎每一次D都是一道简单DP吧hh…

这次的D是令

f[i][j] 表示前i位,最后一位是j(j属于0~9)的方案数
线性DP,顺着递推一定能够得到结果,转移方程:
cnt[i][j*a[i]%10]=(cnt[i][j*a[i]%10]+cnt[i-1][j])%mod;
cnt[i][(j+a[i])%10]=(cnt[i][(j+a[i])%10]+cnt[i-1][j])%mod;
分别表示当前这一位可以如何由上一位转移过来
#include<bits/stdc++.h>
using namespace std;
//================================
#define debug(a) cout << #a": " << a << endl;
#define N 100010
//================================
typedef pair<int,int> pii;
#define x first
#define y second
typedef long long LL; typedef unsigned long long ULL; typedef long double LD;
inline LL read() { LL s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar())    s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; }
inline void print(LL x, int op = 10) { if (!x) { putchar('0'); if (op)  putchar(op); return; }  char F[40]; LL tmp = x > 0 ? x : -x; if (x < 0)putchar('-');  int cnt = 0;    while (tmp > 0) { F[cnt++] = tmp % 10 + '0';     tmp /= 10; }    while (cnt > 0)putchar(F[--cnt]);    if (op) putchar(op); }
//================================= 
const int mod=998244353;
int n;
int a[N],cnt[N][10];

//=================================
int main(){
    n=read();
    for(int i=1;i<=n;i++)
    	a[i]=read();
    cnt[1][a[1]]=1;
    for(int i=2;i<=n;i++){
    	for(int j=0;j<10;j++){
    		cnt[i][j*a[i]%10]=(cnt[i][j*a[i]%10]+cnt[i-1][j])%mod;
    		cnt[i][(j+a[i])%10]=(cnt[i][(j+a[i])%10]+cnt[i-1][j])%mod;
    	}
    }
    
    for(int i=0;i<10;i++)
    	print(cnt[n][i]);
    
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值