Florist shop window (Flower)

Source: Internet
Author: User
Tags gcd

Flower shop window (flower) title description

A flower shop existing F bouquet, each bouquet of flowers are different, at the same time at least the same number of vases, are placed in the order of a row, the position of the vase is fixed, from left to right by 1 to v sequential numbering, V is the number of vases. The bouquet can be moved, and each bundle of flowers is identified by an integer of 1: to F. If I

Input

Line 1th two integers f and V, respectively, bouquet number and vase number (1≤f≤100,f≤v≤i00). Next is the matrix AIJ, which has an I row, j integers per line, and hij represents the aesthetic value of the bouquet I placed in the Vase J.

Output

The 1th line is an integer, which is the maximum aesthetic value; Next there is an F line, two numbers per line, and a number for that bouquet of flowers into that vase.

Sample input
3 23-5 -24 165 21-4 23-21 5  -4-20 20
Sample output
532 4 5
Analysis: Dp[i][j] represents the first I flower into the first J Vase, and the first flower in the first J vase in the maximum aesthetic value, then
Dp[i][j]=max (Dp[i-1][i-1],dp[i-1][i],..., dp[i-1][j-1]) +a[i][j];
PRE[I][J] Record the i-1 flower vase number, output recursive back output can be;
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<ext/rope>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineVI vector<int>#definePII pair<int,int>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e2+Ten;Const intdis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;using namespace__gnu_cxx;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p;p=p*p;q>>=1;}returnF;}intN,M,MA,DP[MAXN][MAXN],A[MAXN][MAXN],PRE[MAXN][MAXN];voidDfsintNowintID) {    if(now==1)return; DFS ( now-1, pre[now-1][id]); printf ("%d", id);}intMain () {inti,j,k,t; scanf ("%d%d",&n,&m); Rep (I,1, N) Rep (J,1, m) scanf ("%d",&A[i][j]); Rep (I,1, m) dp[1][i]=a[1][i]; Rep (I,2, N) {         for(j=i;j<=m;j++)        {             for(k=i-1; k<=j-1; k++)            {                if(dp[i][j]<dp[i-1][k]+A[i][j]) dp[i][j]=dp[i-1][k]+a[i][j],pre[i][j]=K; } }} ma=N; Rep (i,n,m)if(Dp[n][i]>dp[n][ma]) ma=i; printf ("%d\n", Dp[n][ma]);    DFS (N,pre[n][ma]); printf ("%d\n", MA); //System ("pause");    return 0;}

Florist shop window (Flower)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.