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 (abc), 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 output
  1. 2
  2. 3
  3. -1
  1. 3
  2. 13
 
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 = ;
  36. char Ch = ' ';
  37. bool Flag = ;
  38. while(!(Ch >= '' && Ch <= ''))
  39. {
  40. if(Ch == '-') Flag ^= ;
  41. Ch = getchar();
  42. }
  43. while(Ch >= '' && Ch <= '')
  44. {
  45. Ret = Ret * + Ch - '';
  46. Ch = getchar();
  47. }
  48. return Flag ? -Ret : Ret;
  49. }
  50.  
  51. const int N = ;
  52. int n;
  53. int dp[N][N], ans[N];
  54.  
  55. inline void Init()
  56. {
  57. dp[][] = ;
  58. for(int i = ; i <= ; i++)
  59. for(int j = ; j <= i; j++)
  60. dp[i][j] = dp[i - ][j] * j + dp[i - ][j - ] * j;
  61. for(int i = ; i <= ; i++)
  62. for(int j = ; 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) == )
  72. {
  73. if(n == -) return;
  74. Solve();
  75. }
  76. }
  77.  
  78. inline void Solve()
  79. {
  80. printf("%d\n", ans[n]);
  81. }
  82.  
  83. int main()
  84. {
  85. freopen("a.in", "r", stdin);
  86. Input();
  87. //Solve();
  88. return ;
  89. }

ural 1142. Relations的更多相关文章

  1. URAL 1142——Relations——————【dp】

    A - Relations Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submi ...

  2. Ural State University Internal Contest October'2000 Junior Session

    POJ 上的一套水题,哈哈~~~,最后一题很恶心,不想写了~~~ Rope Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7 ...

  3. mysqldump: Got error: 1142: SELECT, LOCK TABLES command denied to user 'root'@'localhost' for table 'accounts' when using LOCK TABLES

    AutoMySQLBackup备份时,出现mysqldump: Got error: 1142: SELECT, LOCK TABLES command denied to user 'root'@' ...

  4. 4.Rabbits and Recurrence Relations

    Problem A sequence is an ordered collection of objects (usually numbers), which are allowed to repea ...

  5. BZOJ 1142: [POI2009]Tab

    1142: [POI2009]Tab Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 213  Solved: 80[Submit][Status][D ...

  6. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  7. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  8. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  9. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

随机推荐

  1. Git命令之从GitHub上下载开源项目

    1,先在本地创建一个目录,作为本地仓库,如: 2,使用Git init 初始化仓库,git初始化完成后,会生成一个隐藏的git文件如: 3,clone Git项目,如: 4,这个项目就是合Github ...

  2. XMPP框架下微信项目总结(5)花名册获取(好友列表)

    ---->概念 ---->添加花名册 ps:添加花名册,启动: 客户端发送请求到服务器获取好友列表信息,同时在项目中创建数据表,并保存好友列表到数据表中. ---->获取服务器保存好 ...

  3. 分享类shareSDK

    1.新浪微博分享时需要注意: [A] 应用信息->基本信息->应用地址 [B] 应用信息->高级信息->OAuth2.0 授权设置 //当使用新浪微博客户端分享的时候需要按照下 ...

  4. valgrind检查C++内存泄漏

    valgrind --tool=memcheck --leak-check=full ./httptest Valgrind 使用 用法: valgrind [options] prog-and-ar ...

  5. 自己动手编译hadoop-2.5.2源码

    搭建环境:Centos x 6.5  64bit (后来:我才知道原来官网上发布的就是64位的,不过这个对我来说是个学习过程,对以后进行其他平台编译的时候有帮助!) 1.安装JDK 我这里用的是64位 ...

  6. Nginx反向代理设置 从80端口转向其他端口

    [root@localhost bin]# netstat -lnutp Active Internet connections (only servers) Proto Recv-Q Send-Q ...

  7. phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护

    转:http://www.cnblogs.com/huangcong/p/3687665.html 首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包 ...

  8. Python 自然语言处理(1) 计数词汇

    Python有一个自然语言处理的工具包,叫做NLTK(Natural Language ToolKit),可以帮助你实现自然语言挖掘,语言建模等等工作.但是没有NLTK,也一样可以实现简单的词类统计. ...

  9. Delphi函数参数传递 默认参数(传值)、var(穿址)、out(输出)、const(常数)四类

    Delphi的参数可以分为:默认参数(传值).var(传址).out(输出).const(常数)四类 可以对比C/C++的相关知识,类比学习. 1.默认参数是传值,不会被改变,例子 function ...

  10. 《图形学》实验三:DDA算法画直线

    开发环境: VC++6.0,OpenGL 实验内容: 使用DDA算法画直线. 实验结果: 代码: #include <gl/glut.h> #include <math.h> ...