您的位置:首页 > 其它

ural 1142. Relations

2015-12-25 20:13 197 查看
原文链接:https://www.geek-share.com/detail/2662045581.html

1142. Relations

Time limit: 1.0 second
Memory limit: 64 MB

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

inputoutput
2
3
-1
3
13
  Tags: none  (hide tags for unsolved problems) Difficulty: 144   题意:计算N个数的大小比较关系的可能情况的总数。 分析:n个数,中间插入一些小于号。其余位置用等号。 等号相连的数的位置没有区别。 问题相当于问将n个数分为几个部分有多少种办法。 dp即可 dp[i][j]表示i个数,分为j组的方案数。 dp[i][j] += dp[i - 1][j] * j   表示第i个数有j中选择加入。 dp[i][j] += dp[i-1][j-1] * j  表示第i个数自立门户,然后这个新的部分插入其他j-1个已经确立大小关系的部分的方法有j种  
1 /**
2 Create By yzx - stupidboy
3 */
4 #include <cstdio>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cmath>
8 #include <deque>
9 #include <vector>
10 #include <queue>
11 #include <iostream>
12 #include <algorithm>
13 #include <map>
14 #include <set>
15 #include <ctime>
16 #include <iomanip>
17 using namespace std;
18 typedef long long LL;
19 typedef double DB;
20 #define MIT (2147483647)
21 #define INF (1000000001)
22 #define MLL (1000000000000000001LL)
23 #define sz(x) ((int) (x).size())
24 #define clr(x, y) memset(x, y, sizeof(x))
25 #define puf push_front
26 #define pub push_back
27 #define pof pop_front
28 #define pob pop_back
29 #define ft first
30 #define sd second
31 #define mk make_pair
32
33 inline int Getint()
34 {
35     int Ret = 0;
36     char Ch = ' ';
37     bool Flag = 0;
38     while(!(Ch >= '0' && Ch <= '9'))
39     {
40         if(Ch == '-') Flag ^= 1;
41         Ch = getchar();
42     }
43     while(Ch >= '0' && Ch <= '9')
44     {
45         Ret = Ret * 10 + Ch - '0';
46         Ch = getchar();
47     }
48     return Flag ? -Ret : Ret;
49 }
50
51 const int N = 15;
52 int n;
53 int dp

, ans
;
54
55 inline void Init()
56 {
57     dp[0][0] = 1;
58     for(int i = 1; i <= 10; i++)
59         for(int j = 1; j <= i; j++)
60             dp[i][j] = dp[i - 1][j] * j + dp[i - 1][j - 1] * j;
61     for(int i = 1; i <= 10; i++)
62         for(int j = 1; j <= i; j++)
63             ans[i] += dp[i][j];
64 }
65
66 inline void Solve();
67
68 inline void Input()
69 {
70     Init();
71     while(scanf("%d", &n) == 1)
72     {
73         if(n == -1) return;
74         Solve();
75     }
76 }
77
78 inline void Solve()
79 {
80     printf("%d\n", ans
);
81 }
82
83 int main()
84 {
85     freopen("a.in", "r", stdin);
86     Input();
87     //Solve();
88     return 0;
89 }
View Code

 

转载于:https://www.cnblogs.com/StupidBoy/p/5076863.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: