当前位置:网站首页>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;
}边栏推荐
- PHP MySQL Update
- c# .net 工具生态
- Five problems of database operation in commodity supermarket system
- Create a new file from templates with bash script - create new file from templates with bash script
- Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
- Keepalived setting does not preempt resources
- How to purchase Google colab members in China
- MinGW compile boost library
- [combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
- QT learning diary 9 - dialog box
猜你喜欢

1147_ Makefile learning_ Target files and dependent files in makefile

Micro service component sentinel console call

Talk about the design and implementation logic of payment process

(9) Opencv Canny edge detection

Draw some simple graphics with MFC

Leetcode Valentine's Day Special - looking for a single dog

MySQL has been stopped in the configuration interface during installation

微服务组件Sentinel控制台调用

Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries

Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
随机推荐
STM32 realizes 74HC595 control
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
(8) HS corner detection
PHP MySQL order by keyword
1146_ SiCp learning notes_ exponentiation
Five problems of database operation in commodity supermarket system
Graduation summary
国内如何购买Google Colab会员
分布式的任务分发框架-Gearman
Research on Swift
QT learning diary 9 - dialog box
[set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela
What is the difference between cloud server and cloud virtual machine
Postfix tips and troubleshooting commands
Wechat applet for the first time
Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
Loop through JSON object list
Detailed explanation of common network attacks
数学公式(测试)
ArrayList analysis 3: delete elements
