Codeforces Round #214 (Div. 2)——Dima and Salad

题目链接

  • 题意:

    一行a[i],一行b[i],a和b是一一对应的。选取任意个数对,使得sigma(a)/ sigma(b)等于k,求这时候sigma(a)的最大值

  • 分析:

    这个题目关键在于对sigma(a)/ sigma(b)== k的处理。对于这种式子,用每个数的比值显然是不行的,因为没法累加;而且是double型,没法DP

    考虑一个每个数对对这个式子的影响,如果每个数都是a = k * b,那么显然是可以的;如果a小于k * b,那么在整体中,当前数对少的数肯定要有一些数对来补偿,也就是说,记x = k * b - a,所有选择的数对的x的和应该是零。

    那么,每个数对其实就变成了一个可正可负的数,求若干个和为零的数的sigma(b)的最大值,正负分开,用背包解决即可

const int MAXN = 110;
const int M = 210000;

int tastes[MAXN], calories[MAXN];
int v[MAXN];
int dp[2][M];

int main()
{
//    freopen("in.txt", "r", stdin);
    int n, m;
    while (~RII(n, m))
    {
        REP(i, n) RI(tastes[i]);
        REP(i, n) RI(calories[i]);
        REP(i, n) v[i] = tastes[i] - calories[i] * m;
        CLR(dp, -INF);
        dp[0][0] = dp[1][0] = 0;
        REP(i, n)
        {
            int cnt = v[i] < 0, val = abs(v[i]);
            FED(j, M - val - 1, 0)
                dp[cnt][j + val] = max(dp[cnt][j + val], dp[cnt][j] + tastes[i]);
        }
        int ans = 0;
        REP(i, M)
            ans = max(ans, dp[0][i] + dp[1][i]);
        if (ans <= 0)
            puts("-1");
        else
            WI(ans);
    }
    return 0;
}

Codeforces Round #214 (Div. 2)——Dima and Salad

时间: 2024-09-30 06:12:31

Codeforces Round #214 (Div. 2)——Dima and Salad的相关文章

Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has t

Codeforces Round #214 (Div. 2)---C. Dima and Salad

Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas

Codeforces Round #262 (Div. 2) 总结:二分

B. Little Dima and Equation 思路:本来前两题都很快做出来的,然后觉得ranting应该可以增加了.然后觉得代码没问题了,又想到了一组cha人的数据,然后就锁了,然后刚锁就被别人cha了看了代码才发现尼玛忘了判断小于10^9了,然后C反正想了好多种方法都不会就没心情了,就这样rating又降了 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #in

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #262 (Div. 2) B

题目: B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following pr

Codeforces Round #260 (Div. 2) A. Laptops(简单题)

题目链接:http://codeforces.com/problemset/problem/456/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops.

Codeforces Round #262 (Div. 2)解题报告

详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http://codeforces.com/contest/460/problem/A 有n双袜子,每天穿一双然后扔掉,每隔m天买一双新袜子,问最多少天后没有袜子穿.. 简单思维题:以前不注重这方面的训练,结果做了比较久,这种题自己边模拟边想.不过要多考虑trick ```c++ int main(){ i