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

(专题DP)?? ?(?_?)? ??

时间:2015-02-09 22:54:08      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

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

题解:动态规划

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\n",a[n]);
26     }
27     return 0;
28 }

 

(专题DP)?? ?(?_?)? ??

标签:

原文地址:http://www.cnblogs.com/awsent/p/4282532.html

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