TC srm 673 300 div1

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+7;
bool cmp(int a,int b)
{
    return a>b;
}
class BearCavalry{
public:
    int countAssignments(vector <int> warriors, vector <int> horses)
    {
        sort(warriors.begin()+1,warriors.end(),cmp);
        sort(horses.begin(),horses.end());
        long long ans = 0;
        for(int i=0;i<horses.size();i++)
        {
            sort(horses.begin(),horses.end());
            int p = warriors[0]*horses[i];
            int k = horses[i];
            horses.erase(horses.begin()+i);
            long long ans2 = 1;
            int flag = 0;
            for(int j=1;j<warriors.size();j++)
            {
                long long tmp = -1;
                for(int t=0;t<horses.size();t++)
                {
                    if(warriors[j]*horses[t]>=p)
                        break;
                    tmp = t;
                }
                //cout<<i<<" "<<j<<" "<<tmp<<endl;
                tmp = tmp + 2 - j;
                //cout<<i<<" "<<j<<" "<<tmp<<endl;
                if(tmp<=0)
                {
                    flag = 1;
                    break;
                }
                ans2 = (ans2 * tmp) % mod;
            }
            if(flag==0)
                ans = (ans + ans2) % mod;
            horses.push_back(k);
        }
        return ans;
    }
};

int main()
{
    BearCavalry C;
    vector<int> a;
    vector<int> b;
    a.push_back(5);a.push_back(8);a.push_back(4);a.push_back(8);
    b.push_back(19);b.push_back(40);b.push_back(25);b.push_back(20);
    printf("%d\n",C.countAssignments(a,b));
}
时间: 2024-10-27 07:30:56

TC srm 673 300 div1的相关文章

[TC SRM 697 div1 lev1] DivisibleSetDiv1

Tutorial:https://apps.topcoder.com/wiki/display/tc/SRM+697#DivisibleSetDiv1 Note:证明过程值得一看. 主要内容:寻找[x1,x2,...,xn]使得满足bi * xi >= S - xi,其中S = x1 + x2 + ... + xn.

TC SRM 638 DIV1 600 NarrowPassage2

Problem Statement 在一个狭长的通道中有$n$只狼,每只狼的体积为$size_i$,如果相邻的两只狼体积不超过$m$,则可以交换位置,求可以有多少种排列. $n≤50,1≤m≤1,000,000,000$ Tutorial 每次选出区间中体积最大的狼,如果其他狼可以越过它,那么即可在整个区间里自由移动,而不能越过它的狼则被隔离到两个区间里,可以分治. 区间总共有$n$只狼,能自由移动的狼个数为$cnt$,那么最后结果等于$$solve(l)*solve(r)*A_{n}^{cnt

TC SRM 637 DIV1 500 PathGame

Problem Statement 给一个2*1000的board,每个格子黑或者白.白格子从左到右连成一条连接第一列和最后一列的path,path上相邻两格有公共边.两人轮流把白格子涂成黑格子,最后一个被迫涂黑格子使path断开的人输.问先手必胜还是必败. (Translated By myq_952) Tutorial 做sg的题有点生(有什么生不生的不就dp嘛) 考虑以一段2*k的全白矩形作为局面,涂黑一个格子会把原局面拆成两个后继局面,然后$n^2$求局面的sg即可 要注意的是,因为本题

[TC SRM 662 div1 lev1] FoxesOfTheRoundTable

转载:http://codeforces.com/blog/entry/19151 Note: 将问题转化为寻找hamiltonian回路问题.证明过程值得一看. Suppose the heights are sorted: h[0] <= h[1] <= h[2] ... In one hand, we know the answer can't be smaller than max{x[i+2] — x[i]}. We can proof this in the following w

TC SRM 655 DIV1 250,500pt

250: 给一个n*n的格子图,每个格子颜色为白色或者红色.假设刚开始都是白色,每次可以涂k*k的一块正方形格子区域,涂成红色或白色,后面涂的可以覆盖前面涂的.给你最终状态,问从初始状态涂任意次数,可不可以涂成最终状态. 挺不错的题,感觉比500有意思.刚开始想简单了,就从前往后枚举,碰到跟最终状态不同就涂.很显然错了.其实实质还是贪心,因为后涂的覆盖前面涂的,所以从最后开始考虑,每次选一块完整颜色相同的出来,涂成该颜色,然后以后该区域的颜色就不会变了,这样贪心的每次选一块可以涂的区域出来,直到

Topcoder Srm 673 Div2 1000 BearPermutations2

\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对于一个长度为 \(n\) 的排列,定义其的贡献为对其建笛卡尔树,树上有两个儿子的节点其左右儿子在原排列中的距离之和,给出 \(n, Mod\),求所有长度为 \(n\) 的排列的贡献之和对 \(Mod\) 取模的值 \(1 \leq n \leq 100\) 解题思路 : 考虑一个最暴力的 \(dp\) ,设

TC SRM 665 DIV2 A LuckyXor 暴力

LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive integer consisting of only the digits 4 and 7.Given an int a, return an int b strictly greater than a, such that a XOR b is a lucky number. (See Notes fo

TC SRM 663 div2 A ChessFloor 暴力

ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a square room. The floor of the room is an N times N grid of unit square tiles. Each tile has some color. You are given the current colors of all tiles in a

TC SRM 663 div2 B AABB 逆推

AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many English words only use the letters A and B. Examples of such words include "AB" (short for abdominal), "BAA" (the noise a sheep makes), &