1 solutions

  • 0
    @ 2022-6-11 19:19:31

    二维背包模板

    #include<bits/stdc++.h>
    using namespace std;
    #define ioio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define endl "\n"
    #define debug(x) cout<<#x<<":"<<x<<endl;
    #define L(k) k<<1
    #define R(k) k<<1|1
    #define P pair
    #define P1 first
    #define P2 second
    #define u_map unordered_map
    #define p_queue priority_queue
    typedef long long ll;
    const double eps = 1e-6;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    const int INF2 = (1 << 31);
    const int N = 4e2 + 7;
    int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
    /*-------------------------------------------------*/
    
    int t,m;
    int n;
    struct st{
    	int t,m,h;
    }p[N];
    int dp[N][N];
    
    int main(){
    	ioio
    	cin>>t>>m;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    		cin>>p[i].t>>p[i].m>>p[i].h;
    	for(int i=1;i<=n;i++)
    		for(int j=t;j>=p[i].t;j--)
    			for(int k=m;k>=p[i].m;k--)
    				dp[j][k]=max(dp[j][k],dp[j-p[i].t][k-p[i].m]+p[i].h);
    	cout<<dp[t][m]<<endl;
    	return 0;
    }
    
    • 1

    Information

    ID
    11
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    2
    Uploaded By