D - Number of Multisets

之前写过一个类似表示的题(2018CCPC吉林赛区——C - Justice),也是让用12,14,18…\frac1 2 ,\frac 14,\frac1 8 \dots21​,41​,81​…凑数,我效仿之前的思路写了个复杂度不清楚的东西(非常爆炸)最终没能过此题

记一下自己写的垃圾代码

#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

然后考虑一下边界条件记忆化搜素即可。

#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相关推荐

  1. arc107_d Number of Multisets dp

    文章目录 题意 dp状态寻求 10月31日晚arc107真题 先吐槽这一场的前四题竟然都是计数题,让我非常震惊. 这是一道十分精巧的dp,对提高自身的dp实力有比较大的帮助,本人强烈推荐. 题意 求含 ...

  2. CodeForces - 981G Magic multisets

    假设我们可以对每个位置快速维护一个数组,记录每个位置有哪些值是已经出现了的,哪些值是没有出现的,这样就可以决定修改的时候到底是 *2 还是 +1了. 但是很可惜,并不存在功能这么强大的数组,所以只能另 ...

  3. 【CodeForces - 1051C 】Vasya and Multisets (模拟)

    题干: Vasya has a multiset ss consisting of nn integer numbers. Vasya calls some number xxnice if it a ...

  4. input属性为number,maxlength不起作用的解决方案

    <input type="text" maxlength="11" /> 效果ok, 当 <input type="number&q ...

  5. ORA-19502: write error on file xxxxx, block number xxxx

    错误现象: 在ORACLE 10g下为表空间IGNITE_EGVSQL01增加数据文件时,报如下错误: SQL> ALTER TABLESPACE IGNITE_EGVSQL01      AD ...

  6. 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 ...

  7. HDU 1711 Number Sequence(KMP算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/ ...

  8. LeetCode 191 Number of 1 Bits

    LeetCode 191 Number of 1 Bits 解法一(较为传统都解法):使用将n不断右移,并与1想&得到1的个数:(也有使用除法/2的,明显除法的运行效率要低于位移) 时间复杂度 ...

  9. [BuildRelease]build number / id

    build number, 也称为build id, 在build release的流程中唯一标示一个build,也是正式的产品的product version 和file version后两位(Ma ...

最新文章

  1. 网传BAT等大厂2020校招传统大厂白菜价!
  2. RDKit | 基于随机森林(RF)预测SARS-CoV 3CL蛋白酶抑制剂的pIC50
  3. TiM:rDNA拷贝数的种内变化影响微生物群落分析吗?
  4. 写好python的代码怎么放在spark上跑_Spark精华问答 | spark的组件构成有哪些?
  5. scala伴生类和半生对象详解
  6. 前端学习(3331):闭包的形式7
  7. linux HBA 卡驱动安装
  8. python 特征选择卡方_为什么pythonsklearn特征选择卡方(chi2)测试不是对称的?
  9. CISP 考试教材《第 1 章 知识域:信息安全保障》知识整理
  10. 【Jenkins】在Pipeline和Ant中使用环境变量
  11. Server-sent events(SSE) EventSource 客户端使用与服务器基础实现(基于Node.js)
  12. 颈椎病自我治疗预防颈椎病
  13. HTML+CSS实现百度网盘首页
  14. MATLAB 将txt文本转化为tif图片格式
  15. Python 用pygame 做一个游戏的开始界面(小白第一篇博客)
  16. Linux 常用小工具
  17. String,无所不在的数据类型
  18. Git版本控制管理——补丁
  19. 汉澳sinox不受openssl心血漏洞影响并分析修复其漏洞代码
  20. Bezier曲线、B样条和NURBS的基本概念

热门文章

  1. 奥的斯服务器状态显示,奥的斯电梯调试服务器(俗称st)按键介绍
  2. java二叉树的深度优先遍历_二叉树的广度优先遍历、深度优先遍历的递归和非递归实现方式...
  3. 京瓷1020怎么打印自检页_[建筑]喷墨打印机如何打印自检页 详细
  4. jax rs mysql_Jersey / JAX-RS ExceptionMapper MySQL
  5. excel筛选排序从小到大_excel表格怎么按字数的多少来排列!
  6. windows安全模式_鲁大师正式挂牌上市,使用鲁大师如何开启笔记本电脑全面节能模式...
  7. php去掉多字节字符,PHP 面试题 - 如果没有 mb 系列函数,如何切割多字节字符串...
  8. [数据结构-严蔚敏版]P46栈的顺序存储表示
  9. 国籍 mysql_国籍表SQL,按首字母升序排序
  10. 深度学习之tensorflow环境搭建