[NOIP Simulation Test]: little odd mining 2 (DP + math)

Topic background

Little bit strange spacecraft opens up unlimited endurance + precise acquisition mode! To this it shipped ore to ore market sources floodlight, the upgrade to unlimited non-probabilistic spacecraft engines.


Title Description

There are $ m + 1 $ planet, numbered from left to right to $ $ $ n-$ 0, $ 0 initially small odd number $ planet.
There are $ n $ of the ore body, ore body at the first $ i $ have $ a_i $ ore unit, on the first $ b_i $ planet.
As the spacecraft using an older engine jump every time it can only move from planet to $ x $ No. of $ x + 4 $ No planet or $ x + 7 $ number planet. Every planet a little odd will go all the ore mining on the planet, seeking the maximum number of ore can be taken to the odd small.
Note that little odd having to eventually reach $ m $ numbers planet.


Input Format

The first row integers $ 2 $ $ n $, $ m $.
Next $ $ n-lines, each integer $ 2 $ $ a_i $, $ b_i $.


Output Format

Output line an integer representing the required results.


Sample

Sample input:

3 13
100 4
10 7
1 11

Sample output:

101


Data range and tips

Sample explained:

First from $ 0 $ to $ 4 $, the second $ 4 from $ 11 to $ $, a total of $ 101 to $ mining ore unit.

data range:

Data for $ 20 \% of $ $ n = 1 $, $ m \ leqslant {10} ^ 5 $.
For $ 40 \% $ data $ n \ leqslant 15 $, $ m \ leqslant {10} ^ 5 $.
For $ 60 \% $ data $ m \ leqslant {10} ^ 5 $.
For $ 100 \% $ data $ n \ leqslant {10} ^ 5 $, $ m \ leqslant {10} ^ 9 $, $ 1 \ leqslant a_i \ leqslant {10} ^ 4 $, $ 1 \ leqslant b_i \ leqslant m $ .


answer

Is still observed data range, found $ 60 \% $ of $ the DP $ good hit, define $ dp [i] $ denotes the maximum number of ore $ I $, then the state transition equation is simple: $ dp [i] = \ max (dp [i-4], dp [i-7]) + x [i] $, where $ x [i] $ $ I $ ore represents the number of points is $ x [i] $.

It is clear that data whether it is time or space are not allowed for $ 100 \% $, it is considered to be optimized.

This time your ideas are likely to think of some kind of data structure of metaphysics, but if you have done $ NOIP \ 2017 \ D1T1 $ Oscar doubts , you probably laughed.

We will find that only $ 4 $ and $ 7 $ two digital largest digital can not make up for the $ 4 \ times 7-4-7 = 17 $, then all greater than $ 17 $ figures are able by the $ 4 $ and $ 7 $ by adding Less scrape out, so we can consider discrete, after two greater than $ 17 from its $ a will to pay $ 18 to $, there is a way to play a lot of students will be on the test card, but the $ a $ this question, however, this would not be the card, this question should be the most rigorous kind of practice.

Time complexity: $ \ Theta (18 \ times n) $.

Expectations score: $ 100 $ points.

Actual score: $ 100 $ points.


Code time

#include<bits/stdc++.h>
using namespace std;
int n,m;
pair<int,int> pos[100010];
int delta[100010];
int dp[2000010];
int Map[2000010];
int p;
int ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		pos[i]=make_pair(b,a);
	}
	sort(pos+1,pos+n+1);
	memset(dp,-0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=n;i++)
		delta[i]=min(18,pos[i].first-pos[i-1].first);
	for(int i=1;i<=n;i++)
	{
		p+=delta[i];
		Map[p]+=pos[i].second;
	}
	for(int i=4;i<=p;i++)
	{
		dp[i]=max(dp[i],dp[i-4]+Map[i]);
		if(i>6)dp[i]=max(dp[i],dp[i-7]+Map[i]);
	}
	for(int i=1;i<=p;i++)ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

rp ++

Guess you like

Origin www.cnblogs.com/wzc521/p/11420998.html