MSBOP 2015 Round2B register

Ended

Participants:6187

Verdict:AC | TLE
Submitted:2015-04-26 14:53:12

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100;
int n,a[maxn];
int ans;
bool p[maxn];
void dfs(int u,int s)
{
    if (u>n) {ans++;return ;}
    for (int i=1;i<=n;i++)
        if (!p[i]&&a[i]!=s)
        {
            p[i]=1;
            dfs(u+1,a[i]);
            p[i]=0;
        }
}
void solve()
{
    scanf("%d",&n);
    char ch[5];
    for (int i=1;i<=n;i++)
    {
        scanf("%s",&ch);
        a[i]=int(ch[0]);
    }
    ans=0;
    memset(p,0,sizeof(p));
    dfs(1,-1);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX