ural 1142. Relations
2015-12-25 20:13
393 查看
1142. Relations
Time limit: 1.0 secondMemory 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
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 = 0; char Ch = ' '; bool Flag = 0; while(!(Ch >= '0' && Ch <= '9')) { if(Ch == '-') Flag ^= 1; Ch = getchar(); } while(Ch >= '0' && Ch <= '9') { Ret = Ret * 10 + Ch - '0'; Ch = getchar(); } return Flag ? -Ret : Ret; } const int N = 15; int n; int dp , ans ; inline void Init() { dp[0][0] = 1; for(int i = 1; i <= 10; i++) for(int j = 1; j <= i; j++) dp[i][j] = dp[i - 1][j] * j + dp[i - 1][j - 1] * j; for(int i = 1; i <= 10; i++) for(int j = 1; j <= i; j++) ans[i] += dp[i][j]; } inline void Solve(); inline void Input() { Init(); while(scanf("%d", &n) == 1) { if(n == -1) return; Solve(); } } inline void Solve() { printf("%d\n", ans ); } int main() { freopen("a.in", "r", stdin); Input(); //Solve(); return 0; }
View Code
相关文章推荐
- 20151225jquery学习笔记---编辑器插件
- Struts 2框架的大致处理流程
- OpenGL填充非凸多边形(网格化)
- popupwindow 与 输入法
- LeetCode 22 - Generate Parentheses
- OpenCV_contrib配置
- 1009. 说反话 (20)
- 万一开车撞人了,一位退休交警教给你的方法,一定要收存!
- 边框文字效果的样式
- 记事本项目
- UVA12304 2D Geometry 110 in 1! 计算几何
- Linking Containers Together
- Linux运维常用命令---find
- 寻求公正是一种心理病
- ubuntu12.04 配置android 编译环境,个人经验小结
- 在android移动设备上登录gmail的时候报password错误解决方法!!!!
- [友盟]使用友盟自带的微博分享时,授权时立马跳到当前程序
- 20151225jquery学习笔记---折叠菜单UI
- 2015/12/25--以前代码总结(02)
- 适配器模式