zoukankan      html  css  js  c++  java
  • (专题DP)⁽⁽ ◟(눈_눈)◞ ⁾⁾

    题意:几个字母比大小的组合数,注意相同字母还有符号

    题解:动态规划

    Description
    Background

    Consider a specific set of comparable objects. Between two objects a and b, there exits one of the following three classified relations:
    a = b
    a < b
    b < a
    Because relation '=' is symmetric, it is not repeated above.
    So, with 3 objects ( a, b, c), there can exist 13 classified relations:
    a = b = c a = b < c c < a = b a < b = c
    b = c < a a = c < b b < a = c a < b < c
    a < c < b b < a < c b < c < a c < a < b
    c < b < a
    Problem

    Given N, determine the number of different classified relations between N objects.
    Input
    Includes many integers N (in the range from 2 to 10), each number on one line. Ends with −1.
    Output
    For each N of input, print the number of classified relations found, each number on one line.
    Sample Input
    input output
    2
    3
    -1
    3
    13

     1 #include<stdio.h>
     2 #include<string.h>
     3 #define N 10
     4 int main()
     5 {
     6     int dp[N][N],a[N];
     7     int n,i,t,j;
     8         memset(dp,0,sizeof(dp));
     9         memset(a,0,sizeof(a));
    10         dp[1][1]=1;
    11         for(i=2;i<N;i++)//i代表有几个字母 
    12         {
    13             a[i]=0;
    14             for(j=1;j<N;j++)//j代表有几个不同字母 
    15             {
    16                 dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j;
    17                            //加一个小于号 //加一个等号 
    18                 a[i]+=dp[i][j];
    19             }
    20         }
    21     while(~scanf("%d",&n))
    22     {
    23         if(n==-1)
    24             break;
    25         printf("%d
    ",a[n]);
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    javaweb登录验证码的实现
    jQuery Ajax 简单的实现跨域请求
    Java Socket长连接示例代码
    Java socket长连接代码实现
    带日期的bean转为json(bean->JSON)
    函数迭代器、生成器、递归
    闭包函数和装饰器
    函数名称空间与作用域
    函数基础
    基本的文件操作
  • 原文地址:https://www.cnblogs.com/awsent/p/4282532.html
Copyright © 2011-2022 走看看