当前位置:网站首页>AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
2022-07-03 17:53:00 【Codiplay】
271. Mr. Yang's photo arrangement - AcWing Question bank
The question :
When taking group photos, the height of each row shall decrease from left to right , The height of each column decreases from the back to the front .
How many plans are there to arrange the location of the group photo
Ideas :

The essence of :
- Simulation operation , Only simulation can operate , Just know that for the current step , Which steps should be updated , You can specialize your “ Each step ”,f It can also be specialized , Because after you find specialization , After finding some features that represent , Reduced the original state space , But the space represented by the answer is still in your specialized state space , In this way, the problem can be specialized , Try and make mistakes through bold speculation and practice , Grasp the essence of the problem .
- aggregate : This set is defined by the property of quantity . Why? ? Because during the simulation, it is found that the current number must be placed on the leftmost side of the same line , And there must be no space above .
First ,1 It must be placed in the upper left corner first , Others cannot undertake this important task . And then 2 Must be in these two positions , Other positions either have spaces on the left , Or there is a space above , Not in accordance with the regulations . therefore , We found that when we put the number , Not even as concerned as the longest ascending subsequence tail Value , Because the title itself has “ monotonicity ”, In other words, you just need to simulate according to the meaning of the topic .
What we care about is : When you want to put the current number , It's time to gather “ shape ”, That is, the number of each line
- The title gives special k The scope of the ,k The maximum is five floors , Special small scope and multi dimension dp relevant
- initialization 、 The order problem of cyclic topology update .
f[0][0][0][0][0] = 1;For this question , Take any one dimension 0, Take any dimension 0, There are many situations in which one dimension is taken or not taken, which is very troublesome to consider , And these f Have practical significance , Corresponding to the actual situation , This question is from all to 0 Updated step by step , So initialization is only used. Initialization is all 0 Of f that will do . For this, we should start from 0 The beginning is basically 0 Initialize to 1, Others do not need to be initialized .
Since from 0 At the beginning, the following topological order must also be equal .
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 31;
ll f[N][N][N][N][N];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
while(cin >> n, n) {
int s[5] = {0};
for (int i = 0; i < n; i ++ ) cin >> s[i];
memset(f, 0, sizeof f);
f[0][0][0][0][0] = 1;
//
for (int a = 0; a <= s[0]; a ++ ) {
for (int b = 0; b <= min(s[1], a); b ++ ) {
for (int c = 0; c <= min(s[2], b); c ++ ) {
for (int d = 0; d <= min(s[3], c); d ++ ) {
for (int e = 0; e <= min(s[4], d); e ++ ) {
ll &x = f[a][b][c][d][e];
if(a && a - 1 >= b) x += f[a - 1][b][c][d][e];
if(b && b - 1 >= c) x += f[a][b - 1][c][d][e];
if(c && c - 1 >= d) x += f[a][b][c - 1][d][e];
if(d && d - 1 >= e) x += f[a][b][c][d - 1][e];
if(e) x += f[a][b][c][d][e - 1];
}
}
}
}
}
cout << f[s[0]][s[1]][s[2]][s[3]][s[4]] << '\n';
}
return 0;
}边栏推荐
- 微服务组件Sentinel控制台调用
- Fedora 21 安装 LAMP 主机服务器
- AcWing 3438. Number system conversion
- [vscode] convert tabs to spaces
- Applet with multiple tabs and Swipers + paging of each tab
- 基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
- Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
- 远程办公工具分享|社区征文
- [combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
- Design limitations of structure type (struct)
猜你喜欢

Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026

Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028

STM32 realizes 74HC595 control

(8) HS corner detection

TCP拥塞控制详解 | 3. 设计空间

POM in idea XML graying solution

PHP MySQL inserts data

聊聊支付流程的设计与实现逻辑
![How to read the source code [debug and observe the source code]](/img/40/a2fca67bcde3c468a739c6990325f4.jpg)
How to read the source code [debug and observe the source code]

基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
随机推荐
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
Hongmeng third training
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Embedded-c language-7
PHP MySQL inserts data
MinGW compile boost library
win32:堆破坏的dump文件分析
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
[combinatorics] generating function (shift property)
Kotlin的协程:上下文
Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
TensorBoard快速入门(Pytorch使用TensorBoard)
[combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
What is the difference between cloud server and cloud virtual machine
List of financial products in 2022
WebView module manages the application window interface to realize the logical control and management operation of multiple windows (Part 1)
[LINUX]CentOS 7 安装MYSQL时报错“No package mysql-server available“No package zabbix-server-mysql availabl
The third day of writing C language by Yabo people
PHP MySQL reads data
