题目:

有N个学生合影,站成左端对齐的k排,每排有 \(N-1,N_2,…N_k\)个人,第一排在最后面。学生的身高互不相同,分别为\(1-N\),并且合影时要求每一排从左往右身高递减,每一列从后往前身高递减,问有多少种安排合影的方案 。\(N <=30, k <=5\)


//此题默认 —— N1 >= N2 >= N3 >= ... >= Nk
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
typedef long long ll;
typedef double db;
const db EPS = 1e-9;
using namespace std; int row[10],n;
ll dp[32][32][32][32][32]; int main()
{
while(~scanf("%d",&n)){
if(!n) break;
memset(row,0,sizeof row);
rep(i,1,n) scanf("%d",&row[i]);
rep(a1,0,row[1])
rep(a2,0,row[2])
rep(a3,0,row[3])
rep(a4,0,row[4])
rep(a5,0,row[5]) dp[a1][a2][a3][a4][a5] = 0;
dp[0][0][0][0][0] = 1;
rep(a1,0,row[1])
rep(a2,0,row[2]){
if(a1 != row[1] && a2 > a1) continue;
rep(a3,0,row[3]){
if(a2 != row[2] && a3 > a2) continue;
rep(a4,0,row[4]){
if(a3 != row[3] && a4 > a3) continue;
rep(a5,0,row[5]){
if(a4 != row[4] && a5 > a4) continue;
if(a1 < row[1])
dp[a1+1][a2][a3][a4][a5] += dp[a1][a2][a3][a4][a5];
if(a2 < row[2] && ((a2 < a1) || (a1 == row[1])))
dp[a1][a2+1][a3][a4][a5] += dp[a1][a2][a3][a4][a5];
if(a3 < row[3] && ((a3 < a2) || (a2 == row[2])))
dp[a1][a2][a3+1][a4][a5] += dp[a1][a2][a3][a4][a5];
if(a4 < row[4] && ((a4 < a3) || (a3 == row[3])))
dp[a1][a2][a3][a4+1][a5] += dp[a1][a2][a3][a4][a5];
if(a5 < row[5] && ((a5 < a4) || (a4 == row[4])))
dp[a1][a2][a3][a4][a5+1] += dp[a1][a2][a3][a4][a5];
}
}
}
}
printf("%lld\n",dp[row[1]][row[2]][row[3]][row[4]][row[5]]);
}
return 0;
}

【POJ 2279】Mr. Young’s Picture Permutations【线性DP】的更多相关文章

  1. 轮廓线DP:poj 2279 Mr. Young's Picture Permutations

    poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...

  2. 【杨氏矩阵+勾长公式】POJ 2279 Mr. Young's Picture Permutations

    Description Mr. Young wishes to take a picture of his class. The students will stand in rows with ea ...

  3. [POJ 2279] Mr. Young's Picture Permutations

    [题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...

  4. POJ P2279 Mr. Young's Picture Permutations 题解

    每日一题 day14 打卡 Analysis 五维dpf[a1,a2,a3,a4,a5]表示各排从左端起分别占了a1,a2,a3,a4,a5个人时合影方案数量然后我们枚举a1,a2,a3,a4,a5从 ...

  5. bzoj 2483: Pku2279 Mr. Young's Picture Permutations -- 钩子公式

    2483: Pku2279 Mr. Young's Picture Permutations Time Limit: 1 Sec  Memory Limit: 128 MB Description   ...

  6. POJ2279 Mr Young's Picture Permutations

    POJ2279 Mr Young's Picture Permutations 描述: 有N个学生合影,站成左对齐的k排,每行分别有N1,N2…NK个人,第一排站最后,第k排站之前.学生身高依次是1… ...

  7. 【题解】POJ2279 Mr.Young′s Picture Permutations dp

    [题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...

  8. Mr. Young's Picture Permutations

    Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增 ...

  9. poj2279——Mr. Young's Picture Permutations

    Description Mr. Young wishes to take a picture of his class. The students will stand in rows with ea ...

  10. poj2279 Mr. Young's Picture Permutations[勾长公式 or 线性DP]

    若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数 ...

随机推荐

  1. 30. 干货系列从零用Rust编写正反向代理,HTTP的组装之旅(中间件)

    wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,四层TCP/UDP转发,七层负载均衡,内网穿透,后续将实现websocket代 ...

  2. 飞腾E2000板载以太网适配

    飞腾E2000板载以太网适配 e20005.4.18macbyt8521 1. 设备树移植 2. MACB驱动移植 3. 网络连通性调试 3-1. MACB驱动环回测试 3-2. YT8521 PHY ...

  3. 【GIT】学习day02 | git环境搭建并将项目进行本地管理【外包杯】

    进入终端 输入GitHub或者给gitee的用户名和邮箱地址 然后依次敲入一下信息 git commit -m "init project" git init git add . ...

  4. 【源码系列#03】Vue3计算属性原理(Computed)

    专栏分享:vue2源码专栏,vue3源码专栏,vue router源码专栏,玩具项目专栏,硬核推荐 欢迎各位ITer关注点赞收藏 语法 传入一个 getter 函数,返回一个默认不可手动修改的 ref ...

  5. 又有新框架上线了,测试、AI 通通有「GitHub 热点速览」

    本周热点之一可能就是 Apple 刚开源便获得 8k+ star 的机器学习框架 mlx,顺带官方开源的 mlx-example(示例仓)也在热门榜上有一席之位,据说它已经跑通了大模型 Llama 7 ...

  6. 吉特日化MES & RabbitMQ 的基本配置

    在吉特日化MES(日化配料系统)中涉及到大量的消息推送,其中针对设备数据的交互(读写) 大量使用了RabbitMQ来进行消息通讯以及程序上的解耦,其中包含使用PDA扫码登录到PLC控制程序,下发生产工 ...

  7. Tensorflow2.0实战之GAN

    本文主要带领读者了解生成对抗神经网络(GAN),并使用提供的face数据集训练网络 GAN 入门 自 2014 年 Ian Goodfellow 的<生成对抗网络(Generative Adve ...

  8. Python给exe添加以管理员运行的属性

    需求 有些应用每次启动都需要用管理员权限运行,比如Python注入dll时,编辑器或cmd就需要以管理员权限运行,不然注入就会失败. 这篇文章用编程怎么修改配置实现打开某个软件都是使用管理员运行,就不 ...

  9. 前端异步编程 —— Promise对象

    在前端编程中,处理一些简短.快速的操作,在主线程中就可以完成. 但是,在处理一些耗时比较长以至于比较明显的事情,比如读取一个大文件或者发出一个网络请求,就需要异步编程来实现,以避免只用主线程时造成页面 ...

  10. 文心一言 VS 讯飞星火 VS chatgpt (168)-- 算法导论13.2 1题

    一.用go语言,写出 RIGHT-ROTATE 的伪代码. 文心一言: 在计算机科学中,右旋转(RIGHT-ROTATE)是一种常见的操作,通常用于数组或链表.以下是一个使用Go语言实现右旋转的伪代码 ...