水题,就是一个暴力。大力出奇迹。

Problem Statement

  There is a narrow passage. Inside the passage there are some wolves. You are given a vector <int>
size that contains the sizes of those wolves, from left to right.





The passage is so narrow that some pairs of wolves cannot pass by each other. More precisely, two adjacent wolves may swap places if and only if the sum of their sizes is
maxSizeSum or less. Assuming that no wolves leave the passage, what is the number of different permutations of wolves in the passage? Note that two wolves are considered different even if they have the same size.





Compute and return the number of permutations of wolves that can be obtained from their initial order by swapping a pair of wolves zero or more times.

Definition

 
Class: NarrowPassage2Easy
Method: count
Parameters: vector <int>, int
Returns: int
Method signature: int count(vector <int> size, int maxSizeSum)
(be sure your method is public)

Limits

 
Time limit (s): 2.000
Memory limit (MB): 256

Constraints

- size will contain between 1 and 6 elements, inclusive.
- Each element in size will be between 1 and 1,000, inclusive.
- maxSizeSum will be between 1 and 1,000, inclusive.

Examples

0)  
 
{1, 2, 3}
3
Returns: 2
From {1, 2, 3}, you can swap 1 and 2 to get {2, 1, 3}. But you can't get other permutations.
1)  
 
{1, 2, 3}
1000
Returns: 6
Here you can swap any two adjacent wolves. Thus, all 3! = 6 permutations are possible.
2)  
 
{1, 2, 3}
4
Returns: 3
You can get {1, 2, 3}, {2, 1, 3} and {2, 3, 1}.
3)  
 
{1,1,1,1,1,1}
2
Returns: 720
All of these wolves are different, even though their sizes are the same. Thus, there are 6! different permutations possible.
4)  
 
{2,4,6,1,3,5}
8
Returns: 60
5)  
 
{1000}
1000
Returns: 1
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
///#define LL __int64
#define LL long long
#define INF 0x7fffffff
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)? 0:x) using namespace std; const int maxn = 1000010; int vis[10][10]; class NarrowPassage2Easy
{
public:
int count(vector <int> size, int maxSizeSum)
{
int len = size.size();
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= len; i++)
{
for(int j = i+1; j <= len; j++)
{
int x = size[i-1]+size[j-1];
if(x > maxSizeSum)
{
///vis[i][j] = 1;
vis[j][i] = 1;
}
}
}
for(int i = 1; i <= len; i++)
{
for(int j = 1; j <= len; j++)
{
cout<<vis[i][j]<<" ";
}
cout<<endl;
}
int sum = 0;
if(len == 1) return 1;
if(len == 2)
{
if(size[0]+size[1] > maxSizeSum) return 1;
return 2;
}
if(len == 3)
{
for(int i = 1; i <= len; i++)
{
for(int j = 1; j <= len; j++)
{
if(i == j) continue;
for(int k = 1; k <= len; k++)
{
if(k == i || k == j) continue;
if(vis[i][j] || vis[i][k] || vis[j][k]) continue;
sum++;
}
}
}
}
if(len == 4)
{
for(int i1 = 1; i1 <= len; i1++)
{
for(int i2= 1; i2 <= len; i2++)
{
if(i1 == i2) continue;
for(int i3 = 1; i3 <= len; i3++)
{
if(i1 == i3 || i2 == i3) continue;
for(int i4 = 1; i4 <= len; i4++)
{
if(i1 == i4 || i2 == i4 || i3 == i4) continue;
if(vis[i1][i2] || vis[i1][i3] || vis[i1][i4]
|| vis[i2][i3] ||vis[i2][i4]
||vis[i3][i4]) continue;
sum++;
}
}
}
}
}
if(len == 5)
{
for(int i1 = 1; i1 <= len; i1++)
{
for(int i2= 1; i2 <= len; i2++)
{
if(i1 == i2) continue;
for(int i3 = 1; i3 <= len; i3++)
{
if(i1 == i3 || i2 == i3) continue;
for(int i4 = 1; i4 <= len; i4++)
{
if(i1 == i4 || i2 == i4 || i3 == i4) continue;
for(int i5 = 1; i5 <= len; i5++)
{
if(i1 == i5 || i2 == i5 || i3 == i5 || i4 == i5) continue;
if(vis[i1][i2] || vis[i1][i3] || vis[i1][i4] || vis[i1][i5]
|| vis[i2][i3] ||vis[i2][i4] || vis[i2][i5]
||vis[i3][i4] || vis[i3][i5]
||vis[i4][i5]) continue;
sum++;
}
}
}
}
}
}
if(len == 6)
{
for(int i1 = 1; i1 <= len; i1++)
{
for(int i2= 1; i2 <= len; i2++)
{
if(i1 == i2) continue;
for(int i3 = 1; i3 <= len; i3++)
{
if(i1 == i3 || i2 == i3) continue;
for(int i4 = 1; i4 <= len; i4++)
{
if(i1 == i4 || i2 == i4 || i3 == i4) continue;
for(int i5 = 1; i5 <= len; i5++)
{
if(i1 == i5 || i2 == i5 || i3 == i5 || i4 == i5) continue;
for(int i6 = 1; i6 <= len; i6++)
{
if(i1 == i6 || i2 == i6 || i3 == i6 || i4 == i6 || i6 == i5) continue;
if(vis[i1][i2] || vis[i1][i3] || vis[i1][i4] || vis[i1][i5] || vis[i1][i6]
|| vis[i2][i3] ||vis[i2][i4] || vis[i2][i5] || vis[i2][i6]
||vis[i3][i4] || vis[i3][i5] || vis[i3][i6]
||vis[i4][i5] || vis[i4][i6]
|| vis[i5][i6]) continue;
sum ++;
}
}
}
}
}
}
}
return sum;
}
};
int main()
{
NarrowPassage2Easy a;
vector<int> f;
f.push_back(189);
f.push_back(266);
cout<<a.count(f, 186)<<endl;;
return 0;
}

Topcoder SRM 638 DIV 2 (大力出奇迹)的更多相关文章

  1. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  2. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  3. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  4. Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索

    最近连续三次TC爆零了,,,我的心好痛. 不知怎么想的,这题把题意理解成,第一次选择j,第二次选择i后,只能从1~i-1.i+1~j找,其实还可以从j+1~n中找,只要没有被选中过就行... [题意] ...

  5. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  6. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  7. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

  8. TopCoder SRM 639 Div.2 500 AliceGameEasy

    题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数 解题思路: 首先判断n(n+1)/2 = (x+y)是 ...

  9. TopCoder SRM 639 Div.2 500 AliceGameEasy --乱搞

    题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数. 解法: 这题是我傻逼了,处理上各种不优越,要使n*( ...

随机推荐

  1. python 字体颜色,背景颜色

  2. scrapy怎么设置带有密码的代理ip base64.encodestring不能用 python3.5,base64库里面的encodestring()被换成了什么?

    自己写爬虫时买的代理ip有密码,在网上查了都是下面这种: 1.在Scrapy工程下新建"middlewares.py": import base64 # Start your mi ...

  3. 第一个 spring Boot 应用通过Docker 来实现构建、运行、发布

    1. Docker 简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙 ...

  4. UVA 10131 Is Bigger Smarter?(DP最长上升子序列)

    Description   Question 1: Is Bigger Smarter? The Problem Some people think that the bigger an elepha ...

  5. [LeetCode] Rotate Image n-by-n矩阵顺时针旋转

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  6. 慕课 python 操作数据库

    test_connection import MySQLdb conn = MySQLdb.Connect( host = '127.0.0.1', port = 3306, user = '**** ...

  7. (1)sqlite基础

    一.安装sqlite 下载页面:http://www.sqlite.org/download.html 1.下载 sqlite-tools-win32-*.zip 和 sqlite-dll-win32 ...

  8. 会话跟踪技术Cookieless

    会话跟踪技术Cookieless   在Web应用中,通常使用Cookie记录用户的状态,如用户名.访问时间等信息.当进行HTTP请求的时候,会自动发送Cookie信息给服务器.服务器接收到,就可以判 ...

  9. luogu P2158 [SDOI2008]仪仗队

    题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...

  10. MQTT协议介绍

    http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.pdf   MQTT 文档 http://mqtt.org/new/wp-c ...