TC srm.673 300
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
Description
给你n(n<=50)匹马和n个人,一匹马和一个人能够组成一个骑兵,这个骑兵的战斗力等于马的战斗力乘以人的战斗力,问你有多少种组合方式满足其他骑兵的战斗力都不超过第0号骑兵。
Input
Output
Sample Input
Sample Output
HINT
题意
题解:
大概就暴力枚举哪匹马和第0号人匹配,后面的骑兵我们按照战斗力从大到小排序之后,对于每一个骑兵二分(或者暴力)找到最多可以选多少匹马,然后就可以容斥做一下就好了~
代码
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std; const int mod = 1e9+;
bool cmp(int a,int b)
{
return a>b;
}
class BearCavalry{
public:
int countAssignments(vector <int> warriors, vector <int> horses)
{
sort(warriors.begin()+,warriors.end(),cmp);
sort(horses.begin(),horses.end());
long long ans = ;
for(int i=;i<horses.size();i++)
{
sort(horses.begin(),horses.end());
int p = warriors[]*horses[i];
int k = horses[i];
horses.erase(horses.begin()+i);
long long ans2 = ;
int flag = ;
for(int j=;j<warriors.size();j++)
{
long long tmp = -;
for(int t=;t<horses.size();t++)
{
if(warriors[j]*horses[t]>=p)
break;
tmp = t;
}
//cout<<i<<" "<<j<<" "<<tmp<<endl;
tmp = tmp + - j;
//cout<<i<<" "<<j<<" "<<tmp<<endl;
if(tmp<=)
{
flag = ;
break;
}
ans2 = (ans2 * tmp) % mod;
}
if(flag==)
ans = (ans + ans2) % mod;
horses.push_back(k);
}
return ans;
}
}; int main()
{
BearCavalry C;
vector<int> a;
vector<int> b;
a.push_back();a.push_back();a.push_back();a.push_back();
b.push_back();b.push_back();b.push_back();b.push_back();
printf("%d\n",C.countAssignments(a,b));
}