1173 - The Vindictive Coach
题目大意:n个不同身高的队员和教练的按照身高排成波浪形……
每个人按照身高由低到高编号,
其中第m个是教练,他必须在第一个,
如果条件允许,排第二的要比m低,
如果条件不允许,即其余人都比教练高,则要让差距尽可能小,求排队方案数。
题目思路:
dp_up[i][j],代表i个人排队,第j个人排在队首,且第二个人小于第一个人的方案数
dp-down[i][j],代表i个人排队,第j个人排在队首,且第二个人大于第一个人的方案数
那么dp_up[i][j] = Sum(dp_down[i-1][j]),因为要求第二个人高于第一个人,所以i<j<=n
那么dp_down[i][j] = Sum(dp_up[i-1][j]),1<=j<j。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define MAXSIZE 505
#define LL unsigned long long using namespace std; LL dp_up[MAXSIZE][MAXSIZE],dp_down[MAXSIZE][MAXSIZE]; LL Solve(int n,int k)
{
if(k==)
{
if(n <= )
return ;
else
return dp_down[n-][];
} LL ans = ;
for(int i=;i<k;i++)
ans += dp_up[n-][i];
return ans;
} int main()
{
memset(dp_up,,sizeof(dp_up));
memset(dp_down,,sizeof(dp_down));
//for(int i=1;i<=50;i++)
dp_up[][] = dp_down[][] = ;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
for(int q=;q<j;q++)
{
dp_down[i][j] += dp_up[i-][q];
} for(int q=j;q<=i;q++)
{
dp_up[i][j] += dp_down[i-][q];
}
}
}
int T,n,k,cns=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
LL ans = Solve(n,k);
printf("Case %d: %llu\n",cns++,ans);
}
return ;
}
1173 - The Vindictive Coach的更多相关文章
- lightoj 1173 - The Vindictive Coach(dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1173 题解:像这种题目显然可以想到n为几时一共有几种排列可以递推出来.然后就是 ...
- LightOJ - 1173 - The Vindictive Coachf(DP)
链接: https://vjudge.net/problem/LightOJ-1173 题意: The coach of a football team, after suffering for ye ...
- URAL 2089 Experienced coach Twosat
Description Misha trains several ACM teams at the university. He is an experienced coach, and he doe ...
- Codeforces Round #181 (Div. 2) B. Coach 带权并查集
B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n ...
- Codevs 1173 最优贸易 2009年NOIP全国联赛提高组
1173 最优贸易 2009年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description [问题描述] C 国有n ...
- Coach(并查集)
Description A programming coach has n students to teach. We know that n is divisible by 3. Let's ass ...
- 轻奢品牌全面崛起 Coach、UGG等纷纷抢滩新兴市场_新闻中心_赢商网
轻奢品牌全面崛起 Coach.UGG等纷纷抢滩新兴市场_新闻中心_赢商网 轻奢品牌全面崛起 Coach.UGG等纷纷抢滩新兴市场
- NEU 1173: 这是物理学的奇迹!! 分解质数
1173: 这是物理学的奇迹!! 题目描述 goagain在做物理电学实验时需要一个2Ω的电阻,但是他发现他的实验台上只剩下了3Ω,4Ω,5Ω,6Ω的电阻若干,于是goagain把两个4Ω的电阻并联起 ...
- WOJ 124. Football Coach 网络流
Problem 1124 - Football Coach Description It is not an easy job to be a coach of a football team. Th ...
随机推荐
- c#UDP协议
UDP协议是不可靠的协议,传输速率快 服务器端: using System; using System.Collections.Generic; using System.Linq; using Sy ...
- POJ 3687 Labeling Balls (top 排序)
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15792 Accepted: 4630 D ...
- (贪心 map) Flying to the Mars hdu1800
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- qml: 软件启用前插入广告;
一般来说,免费软件或者部分商业软件在发布前都会放一些广告在软件上. 下面是我自己的方案(哪位有更好的方案,请告知,先谢): ...... ApplicationWindow{ visible: !ad ...
- 洛谷P1228 分治
https://www.luogu.org/problemnew/show/P1228 我真傻,真的,我单知道这种题目可以用dfs剪枝过,没有想到还能构造分治,当我敲了一发dfs上去的时候,只看到一个 ...
- webpack打包内存溢出的解决方法
由于项目文件越来越多,最终导致在打包时报javaScript heap out of memory错误 解决方案: 1.增加v8内存 使用increase-memory-limit 1)安装 npm ...
- jenkins 基本配置
修改jenkins使用用户和启动端口 //yum 安装 cat /etc/sysconfig/jenkins 安装完后安装maven插件 设置jenkins项目存放目录 系统管理---->系统设 ...
- 《玩转Django2.0》读书笔记-探究视图
<玩转Django2.0>读书笔记-探究视图 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 视图(View)是Django的MTV架构模式的V部分,主要负责处理用户请求 ...
- 14、JDBC-DbUtils-API
DbUtils /** * DbUtils :提供如关闭连接.装载 JDBC 驱动等操作的工具类,里面方法都是静态的. * * public static void close(…) throws j ...
- JAVA核心技术I---JAVA基础知识(数据类型)
一:基本类型 –boolean 布尔 –byte 字节 –short/int/long 短整数/整数/长整数 –float/double 浮点数 –char 字符 (一)boolean 只有true, ...