DES:给出三种材料A,B,C每种的个数。然后组合AB,BC,AC的利润。问能获得的最大利润是多少。

开始一点思路都没有。然后发现可以枚举其中两种的个数。那么最后一种就确定了。还是感觉很机智。

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    int t;
    int ab, bc, ac;
    int a, b, c;
    scanf("%d\n", &t);
    while(t--)
    {
        scanf("%d%d%d%d%d%d", &a, &b, &c, &ab, &bc, &ac);
        int ans = 0;
        //cout << "ab bc ac\n";
        for (int i=0; i<=a; ++i) //ab
        {
            for (int j=0; j<=b-i; ++j) //bc
            {
                int tt;
                if (a-i > c-j) tt = c-j;  //ac
                else tt = a-i;
                if (tt < 0) continue;
                //cout << tt << "==\n";
                if (i+j>b || i+tt>a || j+tt>c) continue;
                int ttt = ab*i + j*bc + tt*ac;
                //cout << i << "==" << j << "==" << tt << endl;
                //cout << ttt << endl;
                if (ans < ttt) ans = ttt;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
View Code

 

posted on 2015-08-14 21:05  小小八  阅读(220)  评论(0编辑  收藏  举报