D. Colored Rectangles

传送门

分析

个人感觉这道题比C简单(一个DP选手最后的尊严)

题目大意是说有三种不同的木棒,第一种木棒有a对,第二种b对,第三种c对,每次取两对不同的木棒组成一个矩形,问最后组成的若干个矩形的面积之和最大是多少

首先我们假设已经选了i个第一种,j个第二种,k个第三种,那么我们可以列成三个状态转移方程

//取第一个和第三个
dp[i + 1][j][k + 1] = max(dp[i + 1][j][k + 1],dp[i][j][k] + 1ll * x[i + 1] * z[k + 1]);
//取第二个和第三个
dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1],dp[i][j][k] + 1ll * y[j + 1] * z[k + 1]);
//取第一个和第二个
dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k],dp[i][j][k] + 1ll * x[i + 1] * y[j + 1]);

最后需要注意一下要让最大的数字相互组合,所以一开始的时候需要将数组sort一下

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
// #pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int T;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N = 210;
int a[N];
int r,g,b;
int x[N],y[N],z[N];
ll dp[N][N][N];

bool cmp(int x,int y){
    return x > y;
}

int main(){
    scanf("%d%d%d",&r,&g,&b);
    for(int i = 1;i <= r;i++) scanf("%d",&x[i]);
    for(int i = 1;i <= g;i++) scanf("%d",&y[i]);
    for(int i = 1;i <= b;i++) scanf("%d",&z[i]);
    sort(x + 1,x + 1 + r,cmp);
    sort(y + 1,y + 1 + g,cmp);
    sort(z + 1,z + 1 + b,cmp);
    ll ans = 0;
    for(int i = 0;i <= r;i++)
        for(int j = 0;j <= g;j++){
            // dp[i + 1][j + 1][0] = max(dp[i + 1][j + 1][0],dp[i][j][k] + 1ll * x[i + 1] * y[k + 1]);
            for(int k = 0;k <= b;k++){
                dp[i + 1][j][k + 1] = max(dp[i + 1][j][k + 1],dp[i][j][k] + 1ll * x[i + 1] * z[k + 1]);
                dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1],dp[i][j][k] + 1ll * y[j + 1] * z[k + 1]);
                dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k],dp[i][j][k] + 1ll * x[i + 1] * y[j + 1]);
                ans = max(dp[i + 1][j][k + 1],ans);
                ans = max(dp[i][j + 1][k + 1],ans);
                ans = max(dp[i + 1][j + 1][k],ans);
            }
        }
    printf("%lld",ans);
}



* This example shows how to use shape-based matching * in order to find a model region and use it for * further tasks. * Here, the additional task consists of reading text * within a certain region, wherefore the image has * to be aliged using the matching transformation. * * Initialization. dev_update_window ('off') dev_close_window () * Initialize visualization. read_image (ReferenceImage, 'board/board_01') get_image_size (ReferenceImage, Width, Height) initialize_visualization (Width / 2, Height / 2, WindowHandle, WindowHandleText) disp_continue_message (WindowHandle, 'black', 'true') disp_description_text (WindowHandleText) * * Define ROIs: * ROI for the shape model. dev_set_window (WindowHandle) dev_display (ReferenceImage) gen_rectangle1 (ROIModel, 60, 535, 185, 900) dev_display (ROIModel) * ROI for the text. gen_rectangle1 (ROIText, 445, 585, 590, 765) dev_display (ROIText) disp_model_message (WindowHandle) stop () * * Prepare the shape-based matching model. reduce_domain (ReferenceImage, ROIModel, ModelImage) * Create shape model and set parameters (offline step). create_generic_shape_model (ModelHandle) * Train the shape model. train_generic_shape_model (ModelImage, ModelHandle) * * Prepare the text model. create_text_model_reader ('auto', 'Industrial_0-9A-Z_Rej.omc', TextModel) * * We look for the reference transformation which we will need * for the alignment. We can extract it by finding the instance * on the reference image. * Set find parameters. set_generic_shape_model_param (ModelHandle, 'num_matches', 1) set_generic_shape_model_param (ModelHandle, 'min_score', 0.5) find_generic_shape_model (ReferenceImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DModel) * * Find the object in other images (online step). for i := 1 to 9 by 1 read_image (SearchImage, 'board/board_' + i$'02') find_generic_shape_model (SearchImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DMatch) * Compute the transformation matrix. hom_mat2d_invert (HomMat2DMatch, HomMat2DMatchInvert) hom_mat2d_compose (HomMat2DModel, HomMat2DMatchInvert, TransformationMatrix) affine_trans_image (SearchImage, ImageAffineTrans, TransformationMatrix, 'constant', 'false') * * Visualization. dev_set_window (WindowHandle) dev_display (SearchImage) get_generic_shape_model_result_object (InstanceObject, MatchResultID, 'all', 'contours') dev_display (InstanceObject) * * Reading text and numbers on the aligned image. reduce_domain (ImageAffineTrans, ROIText, ImageOCR) find_text (ImageOCR, TextModel, TextResultID) get_text_object (Characters, TextResultID, 'all_lines') get_text_result (TextResultID, 'class', RecognizedText) * * Visualization. dev_set_window (WindowHandleText) dev_display (ImageAffineTrans) dev_set_colored (12) dev_display (Characters) disp_finding_text (Characters, WindowHandle, WindowHandleText, RecognizedText) wait_seconds (0.5) endfor disp_end_of_program_message (WindowHandle, 'black', 'true') stop () dev_close_window ()
06-02
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值