题目:点击打开链接
题意:定义一个数列是“好的”:第一个数字a[0]为数列长度+1。定义一个数列的子序列是“好的”:这个子序列能分割成几个“好的”数列。给出一个数列,求“好的”子序列的数目。
分析:定义dp[i]为以a[i]为开头的好序列数目,第一种情况很好求,第二种情况有点难想,应该从后往前遍历,先计算第一种情况,然后累加之后的情况。(dp[i]代表以i开始的符合要求的序列数,j是我们列举出的i之后一个字符串的开始地址,这里的C是组合数,dp[i] += C(j - i - 1, A[i] )* dp[j];)
代码:

#pragma comment(linker, "/STACK:102400000,102400000")///手动扩栈
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
#define debug test
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define eps 1e-10
#define mod 998244353
#define PI acos(-1.0)
const int N = 1e6+10;ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
int to[4][2]={{-1,0},{1,0},{0,-1},{0,1}};ll n,a[N],dp[N],s[N],ans,fac[N];ll qp(ll x,ll y) {ll s=1;while(y) {if(y&1) s=s*x%mod;x=x*x%mod;y>>=1;}return s;
}ll C(ll x,ll y) {if(x<0||y<0) return 0;else return fac[x]*qp(fac[y],mod-2)%mod*qp(fac[x-y],mod-2)%mod;
}int main() {///重定向语句:ifsteam cin("C:\\xxx\\xxx\\xxx.xxx");ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);#ifndef debugfreopen("C:\\Users\\Administrator\\Desktop\\data.in","r",stdin);#endiffac[0]=1;for(int i=1;i<=1005;i++) fac[i]=fac[i-1]*i%mod;cin>>n;for(int i=1;i<=n;i++) cin>>a[i];for(int i=n-1;i>=1;i--) {if(a[i]>0&&( n-i >=a[i])) {dp[i] += C(n-i,a[i]);for(int j=i+a[i]+1;j<=n;j++)dp[i] = (dp[i]+C(j-i-1,a[i])*dp[j]%mod)%mod;}}for(int i=1;i<=n;i++)ans = (ans + dp[i])%mod;cout<<ans<<endl;return 0;
}

Codeforces 1000D Yet Another Problem On a Subsequence相关推荐

  1. Codeforces 1000D Yet Another Problem On a Subsequence 动态规划

    D. Yet Another Problem On a Subsequence time limit per test 2 seconds memory limit per test 256 mega ...

  2. Codeforces 1000D Yet Another Problem On a Subsequence 【dp】【组合数学】

    难点在于怎么想dp,我一开始想dp[i][j]代表前i个数挑j个能组成多少个good sebsequence,最后把dp[n][ 2到n ]加起来就行,但想不出来转移方程怎么做.后来想到我这么想是不对 ...

  3. CodeForces - 1000D Yet Another Problem On a Subsequence(动态规划+组合数学)

    题目链接:点击查看 题目大意:给出n个数字组成的序列,现在规定"好数组"指的是一个连续序列a1,a2,...ak的a1=k-1,再规定"好序列"是可以分为若干个 ...

  4. CodeForces - 1000D Yet Another Problem On a Subsequence

    题面在这里! 好智障的一个dp啊,一段开头的数字相当于下面要跟多少个数,直接滚动数组dp就行了... #include<bits/stdc++.h> #define ll long lon ...

  5. D - Yet Another Problem On a Subsequence CodeForces - 1000D (DP,组合数学)

    D - Yet Another Problem On a Subsequence CodeForces - 1000D The sequence of integers a1,a2,-,aka1,a2 ...

  6. CodeForces - 1000D:Yet Another Problem On a Subsequence (DP+组合数)

    CodeForces - 1000D:Yet Another Problem On a Subsequence (DP+组合数) 题目大意:这题目啊,贼难理解- 定义一个数列是"好的&quo ...

  7. CodeForces - 1000D D. Yet Another Problem On a Subsequence 好题

    D. Yet Another Problem On a Subsequence time limit per test 2 seconds memory limit per test 256 mega ...

  8. Codeforces 776D The Door Problem

    题目链接:http://codeforces.com/contest/776/problem/D 把每一个钥匙拆成两个点${x,x+m}$,分别表示选不选这把钥匙. 我们知道一扇门一定对应了两把钥匙. ...

  9. codeforces C. Sonya and Problem Wihtout a Legend(dp or 思维)

    题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i ...

最新文章

  1. SylixOS 基于STM32平台的GPIO模仿I2C总线的驱动开发流程
  2. 最小最大定理 java_Java基础50道经典练习题(35)——最大最小交换
  3. 计算机系统概论寻址空间,自考《计算机系统结构》重点知识概论:数据表示(二)...
  4. LVITEM结构-列表视图控件的一个数据结构
  5. 分析脚本文件AndroidInitProcess分析心得(1)
  6. Qt 第一步 HelloWorld 的第一个程序
  7. leetcode209. 长度最小的子数组(暴力+滑动窗口)
  8. 美团客户端响应式框架 EasyReact 开源啦
  9. 华为荣耀9x怎么解账户锁_跟华为毫无关系的荣耀为何不值得买?
  10. 易辅客栈-编写手游模拟器辅助脚本-征途
  11. 关于富文本编辑器froala editor和百度Ueditor使用问题
  12. 计算机部分应用显示模糊,win10系统打开部分软件字体总显示模糊的解决方法
  13. 第七周 项目4 - 队列数组
  14. 详细且通俗讲解轻量级神经网络——MobileNets【V1、V2、V3】
  15. (CRON) info (No MTA installed, discarding output)” error in the syslog
  16. 学习TypeScrip2(任意类型)
  17. 电脑网正常,除了IE之外其他浏览器都能正常上网,IE不能上网解决办法
  18. Accept和Content-type的意思
  19. Oracle EBS 12.2.7系统克隆教程
  20. java解析xml文件练习——通过应用包名获取应用图标即其他信息(基于魅族应用商店)...

热门文章

  1. vmware Workstation设置bios启动
  2. 甲方安全之安卓App第三方加固对比
  3. mysql中返回上级_MySql 获取当前节点及递归所有上级节点
  4. 联想 android电视,手机电视无线连 联想电视多屏互动详解
  5. java二维数组遍历后转为一维数组_Excel 数组
  6. 青岛财政局计算机专家招聘,中共青岛市财政局委员会关于丁莉萍等9名同志续聘职务的通知...
  7. python画名字七十周年快乐用英语怎么说_一周年快乐的英语怎么说?
  8. 语音翻译app排行十大最好用的语音识别翻译软件
  9. ECG分析:基于深度学习的ECG心律失常分类入门(5)
  10. Zookeeper 原生客户端、可视化工具 ZooInspector 、Apache Curator