Total Submit: 428 Accepted: 64 Special Judge: No
Xiaoming took the flight MH370 on March 8, 2014 to China to take the ACM contest in WHU. Unfortunately, when the airplane crossing the ocean, a beam of mystical light suddenly lit up the sky and all the passengers with the airplane were transferred to another desert planet.
When waking up, Xiaoming found himself lying on a planet with many precious stones. He found that:
There are n precious stones lying on the planet, each of them has 2 positive values ai and bi. Each time Xiaoming can take the ith of the stones ,after that, all of the stones’ aj (NOT including the stones Xiaoming has taken) will cut down bi units.
Xiaoming could choose arbitrary number (zero is permitted) of the stones in any order. Thus, he wanted to maximize the sum of all the stones he has been chosen. Please help him.
First line of each test case consists of one integer n with 1 <= n <= 1000.
Then each of the following n lines contains two values ai and bi.( 1<= ai<=1000, 1<= bi<=1000)
Input is terminated by a value of zero (0) for n.
100 100
3
2 1
3 1
4 1
0
6
Source
题目大意:
有n堆石头,每拿一堆(假设是第i堆),没有被拿的石头堆的a都要减去bi,求能够拿的a的和的最大值。
dp[i][j]表示第i为,再装j个达到最大值
ac代码
Problem id: 1538 Username: kxh1995
Memory: 9308KB Time: 80ms
Language: C++ Result: Accepted
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define max(a,b) (a>b?a:b)
LL dp[1010][1010];
struct s
{
LL a,b;
}stone[1010];
int cmp(s c ,s d)
{
return c.b<d.b;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF,n)
{
int i,j;
for(i=1;i<=n;i++)
{
scanf("%lld%lld",&stone[i].a,&stone[i].b);
}
sort(stone+1,stone+1+n,cmp);
memset(dp,-INF,sizeof(dp));
for(i=0;i<=n;i++)
{
dp[0][i]=0;
}
for(i=1;i<=n;i++)
{
for(j=0;j<=n;j++)
{
dp[i][j]=max(dp[i-1][j],dp[i-1][j+1]+stone[i].a-stone[i].b*j);
}
}
printf("%lld\n",dp[n][0]);
}
}
本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR、SLAM等,并探讨了其在实际应用中的作用。
788

被折叠的 条评论
为什么被折叠?



