"Blue Bridge Cup" c ++ Province Group B preliminary round match test frequency 2018 Blue Bridge (Mobile Phone Throwing) - Dynamic Programming

Transfer Portal

Title Description

Residents temper x planet is not very good, but fortunately they get angry only when abnormal behavior is: throw the phone.
The major manufacturers also have introduced a variety of shatterproof phone. x planet Bureau of Quality Supervision provides ruggedness phone must be tested and assessed by a shatterproof index before it allows the traded.
x planet there are many towering tower, just can be used for ruggedness testing.
Each layer height of the tower are the same, and the earth is slightly different, they are not the first layer of the ground, but the equivalent of our second floor.
If the phone did not go broke from Layer 7 dropped, but the 8th floor broke, the phone ruggedness index = 7.
In particular, if the phone is dropped from the first layer 1 is broken opinions, the ruggedness index = 0.
If the tower to the top of the n-layer did not throw broken, the ruggedness index = n
order to reduce the number of tests, a sample from each of the three mobile phone manufacturers to take the test.
Tower high of a test of the 1000 level, if we always use the best strategy, most need to be tested in the worst luck in order to determine how many times the phone ruggedness index it?

Export

Output represents an integer answer

 

Idea: describe the optimal substructure property

It is clear that only a cell phone when the guarantee can test out the index is to measure up layer by layer from the first layer to start.

The two phones have the time, you can use cut-and-conquer thoughts will remove a portion of the floor. Suppose a total of n floors, the first mobile phone fell from k layer, then we are faced with two cases after fall

1. broke, it can be determined should be broken floor layer 1 to the k-th layer (n> = k), a total of k layer.

2. not broken, broken floors may be determined to be the first k + 1 layer to the n-th layer, co-nk layer.

Can be seen starting from the second throw the phone, to get an answer before, every time we solve a number of layers on a subset of the range is a range of mobile phone throwing, throw the phone so we can draw the problem with optimal substructure property .

The third step: Solving ruggedness index

Ask what is located

dp [i] [j] indicates the status: i still remaining floors not identified, left j phone uses the best strategy, the highest number required in the worst luck.

The second step is obtained the following equation

AC Code:

 

#include <iostream>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include <vector>
#include<iomanip>
#include <queue>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<stddef.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
int main(){
    int dp[1010][10];
    int n=1000,m=3;
    for(int i=1;i<=n;i++)
        dp[i][1]=i;
    for(int j=2;j<=m;j++){
        for(int i=1;i<=n;i++){
            dp[i][j]=0x3f3f3f3f;
            for(int k=2;k<=i;k++)
                dp[i][j]=min(dp[i][j],max(dp[k-1][j-1]+1,dp[i-k][j]+1));
        }

    }
    cout<<dp[n][m]<<endl;
    return 0;
}

 

Published 350 original articles · won praise 715 · views 50000 +

Guess you like

Origin blog.csdn.net/ZCY19990813/article/details/104077389