D - Permutation Counting
http://acm.hdu.edu.cn/showproblem.php?pid=6880
根据长度为n的排列a,构造长度n-1的序列b

思路:DP
官方题解:

代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
//const int maxn=1e5+10;
const int maxn = 5010;
//const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7; int A[maxn] = {0};
int P[maxn][maxn] = {0};
int main()
{
int n = 0 , ans = 0;
int T = 0;
cin >> T; while(T--)
{
cin >> n;
for(int i = 0;i < n;i++)
{
if(i < n-1)
{
cin >> A[i];
}
for(int j = 0;j < n;j++)
{
P[i][j] = 0;
}
}
P[1][0] = A[0];
P[1][1] = !A[0];
for(int i = 1;i < n-1;i++)
{
if(A[i])
{
for(int j = 0;j < i;j++)
{
P[i+1][i-j] = (P[i+1][i-j+1] + P[i][i-j]) % mod;
}
P[i+1][i+1] = 0;
}
else
{
P[i+1][1] = 0;
for(int j = 1;j < i+1;j++)
{
P[i+1][j] = (P[i][j-1] + P[i+1][j-1]) % mod;
}
}
}
for(int i = 0;i < n;i++)
{
ans = (ans + P[n][i]) % mod;
}
cout << ans << endl;
}
return 0;
}
D - Permutation Counting的更多相关文章
- hdu 3664 Permutation Counting(水DP)
Permutation Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU3664 Permutation Counting
Permutation Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU - 3664 Permutation Counting 排列规律dp
Permutation Counting Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the ...
- hdu3664 Permutation Counting(dp)
hdu3664 Permutation Counting 题目传送门 题意: 在一个序列中,如果有k个数满足a[i]>i:那么这个序列的E值为k,问你 在n的全排列中,有多少个排列是恰好是E值为 ...
- H. Permutation Counting 判环,计数,拓扑
H. Permutation Counting 2022/7/28 传送门:https://codeforces.com/group/5zHJ4CTyoU/contest/392060/problem ...
- HDU - 3664 Permutation Counting
Discription Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of ...
- HDU 3664 Permutation Counting (DP)
题意:给一个 n,求在 n 的所有排列中,恰好有 k 个数a[i] > i 的个数. 析:很明显是DP,搞了好久才搞出来,觉得自己DP,实在是太low了,思路是这样的. dp[i][j]表示 i ...
- HDU 6880 Permutation Counting dp
题意: 给你一个n和一个长度为n-1的由0/1构成的b序列 你需要从[1,n]中构造出来一个满足b序列的序列 我们设使用[1,n]构成的序列为a,那么如果ai>ai+1,那么bi=1,否则bi= ...
- UVALive 5971
Problem J Permutation Counting Dexter considers a permutation of first N natural numbers good if it ...
- LeetCode_Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
随机推荐
- CV中常用Backbone-3:Clip/SAM原理以及代码操作
前面已经介绍了简单的视觉编码器,这里主要介绍多模态中使用比较多的两种backbone:1.Clip:2.SAM.对于这两个backbone简单介绍基本原理,主要是讨论使用这个backbone. 1.C ...
- win10系统 wsappx消耗内存导致死机
问题描述:win10系统开机后,wsappx内存占用率一路飙升,直至电脑蓝屏,手动kill后,过一会死灰复燃. 问题解决:win+R输入 regedit 跳转注册表编辑器,找到 HKEY_LOCAL_ ...
- 计算机网络-TCP/IP知识点
快速以太网数据帧有效载荷的最小长度为 46 字节(参考:Ethernet Frame Calculations) 实战 (2012 408考研真题 47)(15分)主机 H 通过快速以太网连接 Int ...
- kali系统在hyper-v上的配置
安装 镜像下载地址 下载: 将压缩包解压,后找到 .bat 文件,以管理员身份运行. 之后便可以在 \(hyper-v\) 管理器中看到其虚拟机. 汉化处理: 在最上面找到终端,点击打开. 1.打开终 ...
- 在idea里面如何配置自己的tomcat
第一:到官网上去下载自己电脑对应的tomcat版本 第二:下载后解压 在bin目录里面找到: 双击打开是不是会出现: 然后再在bin里面找到:shutdown.bat 双击给他关闭了 第三:在我的电脑 ...
- 深入浅出容器学习--Docker数据卷
一.Docker数据卷 Docker镜像是由多个文件系统(只读层)叠加而成,当启动一个容器的时候,Docker会加载只读镜像层并在其上(镜像栈顶部)添加一个读写层.如果运行中的容器修改了现有的一个已经 ...
- 函数使用十四:BAPI_PO_CREATE1
*&---------------------------------------------------------------------* *& Report ZBAPI_PO_ ...
- 从零开始实现简易版Netty(一) MyNetty Reactor模式
从零开始实现简易版Netty(一) MyNetty Reactor模式 自从18年作为一个java程序员入行以来,所接触到的大量组件如dubbo.rocketmq.redisson等都是基于netty ...
- Solon Flow:轻量级流程编排引擎,让业务逻辑更优雅
在当今快速迭代的软件开发环境中,如何高效地管理和执行业务流程成为了开发者面临的重要挑战.Solon Flow作为Solon生态中的流程编排引擎,以其轻量级.高灵活性和强大的表达能力,为开发者提供了一种 ...
- CSP-S 2024 游寄
我不曾忘记 很好听的草神歌,打算推完经过就推这个 . 我的破木箱 装满枯萎的花 放不下 光与壤 和新鲜的愿望 如果能飞翔 去高高的地方 撒一张 梦的网 收集爱的回响 你也在听吗 落单的孩子啊 别害怕 ...