繁华模拟赛 最优得分

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
using namespace std;
const int maxn = 1005,maxt = 3005,maxint = 987654321;
struct query{
    ll a;
    ll b;
    ll c;
    friend bool operator <(query x,query y){
        return y.b * x.c < x.b * y.c; 
    }
};
int n,t,dp[maxt];
query q[maxn];
void input(){
    cin>>n>>t;
    for(int i = 1;i <= n;i++){
        scanf("%d%d%d",&q[i].a,&q[i].b,&q[i].c);
    }
    sort(q+1,q+1+n);
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
}
void work(){
    for(int i = 1;i <= n;i++){
        for(int j = t;j >= q[i].c;j--){
            if(dp[j-q[i].c] != -1 && dp[j] < dp[j-q[i].c] + q[i].a - q[i].b * j)
                dp[j] = dp[j-q[i].c] + q[i].a - q[i].b * j;
        }
    }
    int ans = 0;
    for(int i = 0;i <= t;i++) ans = max(ans,dp[i]);
    cout<<ans<<endl;
}
int main(){
    //freopen("score.in","r",stdin);
    //freopen("score.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        input();
        work();
    }
    return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<ctime>
#define INF 1000000000
#define N 3005
#define fi first
#define se second
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
struct Data
{
    int a,b,c;
}p[N];

bool operator < (Data a,Data b)
{
    return a.c*b.b<b.c*a.b;
}

inline void upd(int &x,int y)
{
    if(x<y) x=y;
}

int dp[N];
int main()
{
    int T,n,t,j,fn,ans=0,i;
    //freopen("score.in","r",stdin);
    //freopen("score.out","w",stdout);
    //int t1=clock();
    cin>>T;
    while(T--)
    {
        ans=0;
        cin>>n>>t;
        for(i=1;i<=n;i++)
            scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c);
        sort(p+1,p+1+n);
        memset(dp,-1,sizeof(dp));
        dp[0]=0;
        for(i=1;i<=n;i++)
        {
            //debug(p[i].a);
            fn=p[i].a-p[i].b*t;
            //debug(fn);
            for(j=t;j>=p[i].c;j--,fn+=p[i].b)
                if(dp[j-p[i].c]!=-1)
                    upd(dp[j],dp[j-p[i].c]+fn);
        }
        for(i=0;i<=t;i++)
            upd(ans,dp[i]);
        cout<<ans<<endl;
    }
    //debug(clock()-t1);
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:102400000,102400000")
//#define O2 __attribute__((optimize("-O2")))

 

posted @ 2016-09-15 17:39  ACforever  阅读(193)  评论(0编辑  收藏  举报