隔板法怎么做啊?

difei 2023-12-30 10:38:39 2023-12-30 10:39:16

#include<bits/stdc++.h>
using namespace std;
const int N=1100;
int w[N],v[N];
long long f[2][100010]; 
int main(){
	int n,m;
	cin>>n>>m;
	for (int i=1;i<=n;i++)cin>>w[i]>>v[i];
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			if (j>=w[i])f[i%2][j]=max(f[(i-1)%2][j],v[i]+f[i%2][j-w[i]]);
			else f[i%2][j]=f[(i-1)%2][j];
		}
	}
	cout<<f[n%2][m]<<endl;
	return 0;
} 

共 4 条回复

tianyichen

!@#¥%……&*(¥#¥%……&¥&**…………()

hnahongyi

这是那道题?

chl2023

#include <bits/stdc++.h> #define endl "\n" using namespace std; long long f[200001]; const int MOD =1000000007; long long aaa(long long x,long long n){ if(n==0) return 1; long long tmp=aaa(x,n/2); tmp=1LLtmptmp%MOD; if(n%2==1) return 1LLtmpx%MOD; else return tmp; } long long c(long long n,long long m){ return 1LLf[n]aaa(f[m],MOD-2)%MODaaa(f[n-m],MOD-2)%MOD; } long long q(long long a,long long b,long long p){ if(b==0) return 1; long long cmp=q(a,b/2,p); cmp=(long long)cmpcmp%p; if(b%2==0) return cmp; else return (long long)cmp*a%p;

} int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freeopen(".in","r",stdin); //freeopen(".out","w",stdout); long long n,k; cin>>n>>k; f[0]=1; for(int i=1;i<=n;i++)f[i]=1LL*f[i-1]*i%MOD; cout<<c(n-1,k-1)%MOD; return 0; }

difei

发过来行吗?