当前位置:网站首页>D - I Hate Non-integer Number(背包dp)
D - I Hate Non-integer Number(背包dp)
2022-08-01 13:22:00 【Harris-H】
D - I Hate Non-integer Number(背包dp)
一开始想到dp,但是开了个三维数组不知道怎么转移。
实际上枚举选取的个数 i i i。
然后遍历 a a a,枚举当前选了 j j j个,模 i i i的余数为 k k k,这里用背包思想简化一维。
// Problem: D - I Hate Non-integer Number
// Contest: AtCoder - AtCoder Beginner Contest 262
// URL: https://atcoder.jp/contests/abc262/tasks/abc262_d
// Memory Limit: 1024 MB
// Time Limit: 2500 ms
// Date: 2022-07-31 23:51:13
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=105,M=2e4+5,inf=0x3f3f3f3f,mod=998244353;
const int hashmod[4] = {
402653189,805306457,1610612741,998244353};
#define mst(a,b) memset(a,b,sizeof a)
#define db double
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y){
if(x<y) x=y;
}
template <typename T>
void cmn(T &x,T y){
if(x>y) x=y;
}
ll a[N];
ll f[N][N];
ll ans;
int main(){
int n;cin>>n;
rep(i,1,n) cin>>a[i];
rep(i,1,n){
mst(f,0);
f[0][0]=1;
for(int u=1;u<=n;u++)
for(int j=i;j;j--)
for(int k=0;k<i;k++){
(f[j][(k+a[u])%i]+=f[j-1][k])%=mod;
}
(ans+=f[i][0])%=mod;
}
cout<<ans;
return 0;
}
边栏推荐
猜你喜欢

postgresql之page分配管理(一)

NebulaGraph v3.2.0 Performance Report

JMP Pro 16.0软件安装包下载及安装教程

shell 中的 分发系统 expect脚本 (传递参数、自动同步文件、指定host和要传输的文件、(构建文件分发系统)(命令批量执行))

响应式2022英文企业官网源码,感觉挺有创意的

Data Mining-04

芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)

搭建LNMT架构

微信UI在线聊天源码 聊天系统PHP采用 PHP 编写的聊天软件,简直就是一个完整的迷你版微信

fh511小风扇主控芯片 便携式小风扇专用8脚IC 三档小风扇升压芯片sop8
随机推荐
SQL functions STR
力扣160题,相交链表
SQL函数 %SQLSTRING
预防和制止家庭暴力 人身安全保护令司法解释今起施行
The obstacles to put Istio into production and how we solve them
SQL function SQRT
uniapp读取和写入文件
珠海首个水环境安全监测系统上线
Detailed explanation of table join
【StoneDB Class】入门第二课:StoneDB 整体架构解析
LeetCode_动态规划_中等_377.组合总和 Ⅳ
树和二叉树的转换
NebulaGraph v3.2.0 性能报告
tensorflow2.0手写数字识别(tensorflow手写体识别)
Grafana 9.0 released, Prometheus and Loki query builders, new navigation, heatmap panels and more!
windows IDEA + PHP+xdebug 断点调试
JMP Pro 16.0 software installation package download and installation tutorial
【码蹄集新手村600题】判断一个数字是否为完全平方数
LeetCode_位运算_简单_405.数字转换为十六进制数
sql中常用到的正则表达