Topcoder SRM 638 DIV 2 (大力出奇迹)_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:54:56
原创
1281人浏览过

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

Problem Statement

  There is a narrow passage. Inside the passage there are some wolves. You are given a vector 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
Returns: int
Method signature: int count(vector 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}
登录后复制
登录后复制
登录后复制
From {1, 2, 3}, you can swap 1 and 2 to get {2, 1, 3}. But you can't get other permutations.
1)  
 
@@######@@
@@######@@
Returns: 2
登录后复制
Here you can swap any two adjacent wolves. Thus, all 3! = 6 permutations are possible.
2)  
 
@@######@@
{1, 2, 3}
登录后复制
登录后复制
登录后复制
You can get {1, 2, 3}, {2, 1, 3} and {2, 3, 1}.
3)  
 
@@######@@
1000
登录后复制
登录后复制
All of these wolves are different, even though their sizes are the same. Thus, there are 6! different permutations possible.
4)  
 
@@######@@
Returns: 6
登录后复制
5)  
 
@@######@@
@@######@@
{1, 2, 3}
登录后复制
登录后复制
登录后复制
Returns: 3
登录后复制


{1,1,1,1,1,1}
登录后复制
Returns: 720
登录后复制
{2,4,6,1,3,5}
登录后复制
Returns: 60
登录后复制
{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;}
登录后复制
HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号