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 ...
随机推荐
- WPF 基于Transform实现画布超出边界触发计算
有些场景需要对画布边界做界限控制,此时需要计算画布的四个方向的界限和极值 先看效果图: 画布在通过RenderTransform 做变换,由于在变换的过程中,实际的宽高没有改变,需要通过Transfo ...
- 6 MyBatis动态SQL之choose(when、otherwise)语句
1 MyBatis动态SQL之if 语句 2 MyBatis动态sql之where标签|转 3 MyBatis动态SQL之set标签|转 4 MyBatis动态SQL之trim元素|转 5 MyBat ...
- Jackson反序列化抛异常:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field的解决方法
目录 需求背景 问题分析 问题解决 使用注解@JsonIgnoreProperties ObjectMapper对象配置FAIL_ON_UNKNOWN_PROPERTIES 需求背景 第三方服务返 ...
- required a bean of type 'org.springframework.jms.core.JmsMessagingTemplate' that could not be found
问题来源: Spring Boot 项目集成 ActiveMQ. 报错内容: Description:Field jmsTemplate in XXX required a bean of t ...
- 2024杭电钉耙1-1003 HDOJ7435 树
本文同步发布于我的网站 Problem 给一棵根为 1 的有根树,点 \(i\) 具有一个权值 \(A_i\) . 定义一个点对的值 \(f(u, v)=\max \left(A_u, A_v\rig ...
- 团队如何限制合适的在制品(WIP)数量
看板之父David Anderson曾说过" 看板的本质是一个很朴素的思想:在制品必须被限制."但对于团队来说,确定一个合适的在制品限制可能是件棘手的事. 在 <看板快速启动 ...
- 【中英】【吴恩达课后编程作业】Course 4 -卷积神经网络 - 第四周作业
[中文][吴恩达课后编程作业]Course 4 - 卷积神经网络 - 第四周作业 - 人脸识别与神经风格转换 上一篇:[课程4 - 第四周测验]※※※※※ [回到目录]※※※※※下一篇:[待撰写-课程 ...
- java-web与jdbc 的使用
1:本地连接数据库的步骤 1 public class LoginDao { 2 3 // jdbc操作的五部曲 4 5 // 1: 导入jar包 6 // 2: 加载驱动 7 // 3: 获取连接 ...
- 了解php当中简单的单例模式
本文由 ChatMoney团队出品 单例模式是一种常用的设计模式,它的核心思想是确保一个类只有一个实例,并提供一个全局访问点来获取这个实例.在 PHP 中实现单例模式通常有三种形式:饿汉式(Eager ...
- vue导出Excel表格各种样式
https://www.cnblogs.com/Awchao/p/14143385.html