链接:

https://vjudge.net/problem/LightOJ-1173

题意:

The coach of a football team, after suffering for years the adverse comments of the media about his tactics, decides to take his revenge by presenting his players in a line-up in such a way that the TV cameras would be compelled to zigzag in a ridiculous bobbing motion, by alternating taller and shorter players. However, the team captain objects that he must be the first of the line by protocolary reasons, and that he wants to be seen in the best possible light: that is, he should not have a taller colleague next to him unless there is no alternative (everyone else is taller than him). Even in this case, the height difference should be as small as possible, while maintaining the zigzag arrangement of the line.

With this condition the coach addresses an expert in computation (i.e. you) to help him find the number of different alignments he may make, knowing that all players have a different height. They are always numbered by stature starting by 1 as the shortest one. Of course the number of players may be arbitrary, provided it does not exceed 50.

思路:

Dp[i][j][0] 记录j开头, 长度为i,同时从大到小开始的顺序。

Dp[i][j][1] 记录j开头, 长度为i,同时从小到大开始的顺序。

对于Dp[i][j][0]累加Dp[i-1][k][1],其中k < j

对于Dp[i][j][1]累加Dp[i-1][k][0],其中j <= k < i

代码:

// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e8+7;
const int MAXN = 1e6+10; ULL Dp[55][55][2];
int n, m; void Init()
{
memset(Dp, 0, sizeof(Dp));
Dp[1][1][0] = Dp[1][1][1] = 1;
for (int i = 2;i <= 50;i++)
{
for (int j = 1;j <= i;j++)
{
for (int k = 1;k < j;k++)
Dp[i][j][0] += Dp[i-1][k][1];
for (int k = j;k < i;k++)
Dp[i][j][1] += Dp[i-1][k][0];
}
}
} int main()
{
// freopen("test.in", "r", stdin);
Init();
int t, cas = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cas);
scanf("%d %d", &n, &m);
ULL ans = 0;
if (m == 1)
{
if (n <= 2)
ans += 1;
else
ans += Dp[n-1][2][0];
}
else
{
for (int i = 1;i < m;i++)
ans += Dp[n-1][i][1];
}
printf(" %llu\n", ans); } return 0;
}

LightOJ - 1173 - The Vindictive Coachf(DP)的更多相关文章

  1. lightoj 1173 - The Vindictive Coach(dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1173 题解:像这种题目显然可以想到n为几时一共有几种排列可以递推出来.然后就是 ...

  2. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  3. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  4. LightOJ 1422 Halloween Costumes 区间dp

    题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ...

  5. LightOJ - 1246 Colorful Board(DP+组合数)

    http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...

  6. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  7. lightoj 1145 - Dice (I)(dp+空间优化+前缀和)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1145 题解:首先只要是dp的值只和上一个状态有关系那么就可以优化一维,然后这题 ...

  8. LightOJ 1248 Dice (III) (期望DP / 几何分布)

    题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...

  9. lightoj 1018 (状态压缩DP)

    设dp[s]表示状态s下所需要的线段的个数,s的二进制中第x位为1就表示该状态下第x个点没被线段覆盖.需要预处理出来在任意两点之间连线所覆盖点的状态O(n^3),然后记忆化搜索即可. #include ...

随机推荐

  1. 14.Python略有小成(自由模块)

    Python(模块) 一.模块定义与分类 ​ 我们说一个函数就是一个功能,那么把一些常用的函数放在一个py文件中,这个文件就称之为模块,模块,就是一些列常用功能的集合体,模块就是文件,存放一堆常用的函 ...

  2. (转)AS3正则:元子符,元序列,标志,数量表达符

    (转)AS3正则:元子符,元序列,标志,数量表达符: AS3正则:元子符,元序列,标志,数量表达符 七月 4th, 2010 归类于 AS3前端技术 作者Linkjun 进行评论 as3正则:元子符, ...

  3. js注意点

    1.在JS中:var a=''; 则 a==0或a==false 结果都为true;  如果是“====” 则为false

  4. WebAPI 之问题记录

    这篇博客是博主的第一篇博客,主要用于webapi学习过程中的问题记录 问题1:  重写OnAuthorization权限验证时,遇到AllowAnonymousAttribute特性不起作用的问题 p ...

  5. web API .net - .net core 对比学习-依赖注入

    今天我们来看一下 .net web api 和 .net core web api依赖注入机制的差异. 首先我们分别在.net web api 和 .net core web api新建文件夹Serv ...

  6. 分布式系统session一致性解决方案

    在单机系统中,不存在Session共享问题,但是在分布式系统中,我们必须实现session共享机制,使得多台应用服务器之间会话统一,如果不进行Session共享会出现数据不一致,比如:会导致请求落到不 ...

  7. iOS进阶之多线程--NSThread详解

    NSThread简介 NSThread是苹果官方提供面向对象操作线程的技术,简单方便,可以直接操作线程对象,不过需要自己控制线程的生命周期.在平时使用很少,最常用到的无非就是 [NSThread cu ...

  8. Jmeter学习笔记(十)——元件的作用域和执行顺序

    jmeter是一个开源的性能测试工具,它可以通过鼠标拖拽来随意改变元件之间的顺序以及元件的父子关系,那么随着它们的顺序和所在的域不同,它们在执行的时候,也会有很多不同. jmeter的test pla ...

  9. keychain不能导出p12证书的解决方法

    点击左边下面的“我的证书”,然后点击右边的证书,打开下面有一个key导出就可以了.

  10. 学而不思则罔 - SAP云平台ABAP编程环境的由来和适用场景

    最近Jerry写了一系列关于SAP云平台ABAP编程环境的技术文章,这些文章都是围绕着在云上的ABAP编程环境的具体知识点来分享,比如要完成一个具体的开发需求,所需要的编程步骤.这些文章陆续收到一些读 ...