首页 > 代码库 > tc srm 636 div2 500

tc srm 636 div2 500

100的数据直接暴力就行,想多了。。。

ac的代码:

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <vector> 8 #define LL __int64 9 const int maxn = 100+10;10 using namespace std;11 int a[maxn], sum;12 13 class SortishDiv214 {15 public:16     int ways(int sortedness, vector <int> seq)17     {18         int f[maxn], len, i, j, ans = 0;19         int cnt = 0, x[maxn];20         len = seq.size();21         memset(f, 0, sizeof(f));22         for(i = 0; i < len; i++)23             f[seq[i]] = 1;24         for(i = 1; i <= len; i++)25             if(f[i]==0)26                 x[cnt++] = i;27         sort(x, x+cnt);28         do29         {30             int y = 0;31             for(i = 0; i < len; i++)32             {33                 if(seq[i]==0) a[i] = x[y++];34                 else a[i] = seq[i];35             }36             sum = 0;37             for(i = 0; i < len; i++)38             for(j = i+1; j < len; j++)39             if(a[j]>a[i])40             sum ++;41             if(sum == sortedness) ans ++;42         }43         while (next_permutation(x,x+cnt));  //数字的全排列44 45         return ans;46     }47 };48 49 /*int main()50 {51     SortishDiv2 s;52     int i, j, n, y, tmp;53     vector<int>v;54     while(1)55     {56         v.clear();57         cin>>n; cin>>y;58         for(i = 0; i < y; i++)59         {60           cin>>tmp;61           v.push_back(tmp);62         }63         cout<<s.ways(n, v)<<endl;64     }65     return 0;66 }*/

 

tc srm 636 div2 500