码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 6177 The King's Ups and Downs DP

时间:2018-01-04 00:22:26      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:set   def   tps   ons   uva   amp   mmm   archive   turn   

orz想了好久好久的排列组合,未果,考虑不全……DP好难啊233333

题目链接戳这里

抛开整体不考虑,我们来考虑一下只有3个人的局部问题:

只要第i-1个人比i矮(高)第i+1个人比i矮(高),i当前位置就是满足题意的

设f[i][j]为排列的第i位为j,而且i-1位比j小

设g[i][j]为排列的第i位位j,而且i-1位比j大

emmmmm明天补

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX= 13e5;
int t,n,m; 
ll dp[25][25];
ll ans[25];
void init()
{
    memset(ans,0,sizeof(ans));
    dp[1][1]=1;
    ans[1]=1;
    for(int i=2;i<25;i++)
     for(int j=2;j<=i;j++)
     {
      dp[i][j]=dp[i-1][i-j+1]+dp[i][j-1];
      ans[i]+=dp[i][j]*2;
     }
}
int main()
{
    cin>>t;
    init();
    while(t--)
    {
        cin>>n>>m;
        cout<<n<<" "<<ans[m]<<endl;
    }
    return 0;
 } 

 

UVA 6177 The King's Ups and Downs DP

标签:set   def   tps   ons   uva   amp   mmm   archive   turn   

原文地址:https://www.cnblogs.com/Egoist-/p/8185798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!