ARC107——D - Number of Multisets
D - Number of Multisets
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=3110;
const int mod=998244353;
int n,k;
int f[20][N][N];
ll dfs(int u,int cnt,int now)
{ if(now+cnt>n) return 0;if(!cnt) return now==n;if(u>12) return 0;if(f[u][cnt][now]!=-1) return f[u][cnt][now];f[u][cnt][now]=0;for(int i=0;i<=cnt;i++)f[u][cnt][now]=(f[u][cnt][now]+dfs(u+1,(cnt-i)*2,now+i))%mod;return f[u][cnt][now];
}
int main()
{//IO;int T=1;//cin>>T;while(T--){memset(f,-1,sizeof f);cin>>n>>k;cout<<dfs(1,k,0)<<'\n';}return 0;
}
这题的正解时划分dp,之前有一个整数划分的题,我用的完全背包做的,一直没用划分dp做,这次遇到题目就不会了hh
大佬题解
状态表示:f(i,j)f_{(i,j)}f(i,j)当前需要选出iii个数的和时jjj的方案数
状态转移:我们把方案划分成两种情况:①至少选择一个1。②不选择1
- 对于①:f(i,j)=f(i−1,j−1)f_{(i,j)}=f_{(i-1,j-1)}f(i,j)=f(i−1,j−1)
- 对于②:不选择111,此时问题转化为:问有多少种选出 iii 个数的方案,满足 i 个数的和为 jjj 。这 iii 个数都须是 12i(i∈[1,∞))\frac{1}{2^i}(i∈[1,∞))2i1(i∈[1,∞)) 的形式。我们考虑这个子问题的限制条件与原问题的限制条件的关系。如果我们将这 iii 个数同时×2×2×2,那么子问题的限制条件就和原问题的限制条件一致了。此时问题转化为求解 f(i,2j)f_{(i,2j)}f(i,2j)
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=3010;
const int mod=998244353;
int f[N][N];
int n,k;
int dfs(int i,int j)
{if(i<=j) return i==j;if(!j) return 0;if(f[i][j]!=-1) return f[i][j];return f[i][j]=(dfs(i-1,j-1)+dfs(i,2*j))%mod;
}
int main()
{//IO;int T=1;//cin>>T;while(T--){memset(f,-1,sizeof f);cin>>n>>k;cout<<dfs(n,k)<<'\n';}return 0;
}
总结:dp的本质时递推,如果能够设计某种表示能够有一种递推关系,那么有可能该解就可以得出答案。
ARC107——D - Number of Multisets相关推荐
- arc107_d Number of Multisets dp
文章目录 题意 dp状态寻求 10月31日晚arc107真题 先吐槽这一场的前四题竟然都是计数题,让我非常震惊. 这是一道十分精巧的dp,对提高自身的dp实力有比较大的帮助,本人强烈推荐. 题意 求含 ...
- CodeForces - 981G Magic multisets
假设我们可以对每个位置快速维护一个数组,记录每个位置有哪些值是已经出现了的,哪些值是没有出现的,这样就可以决定修改的时候到底是 *2 还是 +1了. 但是很可惜,并不存在功能这么强大的数组,所以只能另 ...
- 【CodeForces - 1051C 】Vasya and Multisets (模拟)
题干: Vasya has a multiset ss consisting of nn integer numbers. Vasya calls some number xxnice if it a ...
- input属性为number,maxlength不起作用的解决方案
<input type="text" maxlength="11" /> 效果ok, 当 <input type="number&q ...
- ORA-19502: write error on file xxxxx, block number xxxx
错误现象: 在ORACLE 10g下为表空间IGNITE_EGVSQL01增加数据文件时,报如下错误: SQL> ALTER TABLESPACE IGNITE_EGVSQL01 AD ...
- LeetCode刷题记录10——434. Number of Segments in a String(easy)
LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...
- HDU 1711 Number Sequence(KMP算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/ ...
- LeetCode 191 Number of 1 Bits
LeetCode 191 Number of 1 Bits 解法一(较为传统都解法):使用将n不断右移,并与1想&得到1的个数:(也有使用除法/2的,明显除法的运行效率要低于位移) 时间复杂度 ...
- [BuildRelease]build number / id
build number, 也称为build id, 在build release的流程中唯一标示一个build,也是正式的产品的product version 和file version后两位(Ma ...
最新文章
- 网传BAT等大厂2020校招传统大厂白菜价!
- RDKit | 基于随机森林(RF)预测SARS-CoV 3CL蛋白酶抑制剂的pIC50
- TiM:rDNA拷贝数的种内变化影响微生物群落分析吗?
- 写好python的代码怎么放在spark上跑_Spark精华问答 | spark的组件构成有哪些?
- scala伴生类和半生对象详解
- 前端学习(3331):闭包的形式7
- linux HBA 卡驱动安装
- python 特征选择卡方_为什么pythonsklearn特征选择卡方(chi2)测试不是对称的?
- CISP 考试教材《第 1 章 知识域:信息安全保障》知识整理
- 【Jenkins】在Pipeline和Ant中使用环境变量
- Server-sent events(SSE) EventSource 客户端使用与服务器基础实现(基于Node.js)
- 颈椎病自我治疗预防颈椎病
- HTML+CSS实现百度网盘首页
- MATLAB 将txt文本转化为tif图片格式
- Python 用pygame 做一个游戏的开始界面(小白第一篇博客)
- Linux 常用小工具
- String,无所不在的数据类型
- Git版本控制管理——补丁
- 汉澳sinox不受openssl心血漏洞影响并分析修复其漏洞代码
- Bezier曲线、B样条和NURBS的基本概念
热门文章
- 奥的斯服务器状态显示,奥的斯电梯调试服务器(俗称st)按键介绍
- java二叉树的深度优先遍历_二叉树的广度优先遍历、深度优先遍历的递归和非递归实现方式...
- 京瓷1020怎么打印自检页_[建筑]喷墨打印机如何打印自检页 详细
- jax rs mysql_Jersey / JAX-RS ExceptionMapper MySQL
- excel筛选排序从小到大_excel表格怎么按字数的多少来排列!
- windows安全模式_鲁大师正式挂牌上市,使用鲁大师如何开启笔记本电脑全面节能模式...
- php去掉多字节字符,PHP 面试题 - 如果没有 mb 系列函数,如何切割多字节字符串...
- [数据结构-严蔚敏版]P46栈的顺序存储表示
- 国籍 mysql_国籍表SQL,按首字母升序排序
- 深度学习之tensorflow环境搭建