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
2
3
-1
3
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种
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n;
int dp[N][N], ans[N]; inline void Init()
{
dp[][] = ;
for(int i = ; i <= ; i++)
for(int j = ; j <= i; j++)
dp[i][j] = dp[i - ][j] * j + dp[i - ][j - ] * j;
for(int i = ; i <= ; i++)
for(int j = ; j <= i; j++)
ans[i] += dp[i][j];
} inline void Solve(); inline void Input()
{
Init();
while(scanf("%d", &n) == )
{
if(n == -) return;
Solve();
}
} inline void Solve()
{
printf("%d\n", ans[n]);
} int main()
{
freopen("a.in", "r", stdin);
Input();
//Solve();
return ;
}

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 、 Cocoapods常用命令

    Git常用命令 1.添加文件   git  add  xxx 2.提交更新到本地  git commit   -m  'local-repo' 3.提交更新    git  push master  ...

  2. JavaWeb学习之JSP常用标签、EL表达式的运算符、JSTL标签库(6)

    1.JSP常用标签 * 只要支持JSP文件,常用标签有可以直接使用 * 格式: jsp:xxxx * jsp:forward ,完成jsp页面的转发 * page属性:转发的地址 <% requ ...

  3. 【JAVA多线程概述】

    一.多线程概述 一个进程中至少有一个线程,每一个线程都有自己运行的内容,这个内容可以称为线程要执行的任务. 不能没一个问题都使用多线程,能使用单线程解决的问题就不要使用多线程解决. 使用多线程的弊端: ...

  4. OCJP(1Z0-851) 模拟题分析(六)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  5. org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:

    详细错误堆栈信息: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" ...

  6. PHPCMS 实现上一篇、下一篇

    方法一:直接调用phpcms系统的函数 <div class="info"> <span>上一篇:<a href="{$previous_p ...

  7. 25条提高Visual Studio编码和调试效率的技巧

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:工欲善其事必先利其器.就算手中已经有了利器,如果能掌握一些使用工具的技巧,让利器更加顺 ...

  8. java调用shell获取返回值

    转自:http://blog.csdn.net/tengdazhang770960436/article/details/12014839 1.shell文件return.sh echo 1 echo ...

  9. Effective C++ 之 Item 6 : 若不想使用编译器自动生成的函数,就该明确拒绝

    Effective C++ chapter 2. 构造 / 析构 / 赋值运算 (Constructors, Destructors, and Assignment Operators) Item 6 ...

  10. Arduino101学习笔记(六)—— 高级IO

    1.位移输出函数(8位) 输入value数据后Arduino会自动把数据移动分配到8个并行输出端. 其中dataPin为连接DS的引脚号, clockPin为连接SH_CP的引脚号, bitOrder ...