数字三角形 #include <bits/stdc++.h> //#define int long long using namespace std; const int N=1e4+10,mod=1e9+7; string s; int n,t,a[N][N],f[N][N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) cin>>a[i][j]; f[1][1]=a[1][1]; for(int i=2;i<=n;i++) for(int j=1;j<=i;j++) f[i][j]=max(f[i-1][j]+a[i][j],f[i-1][j-1]+a[i][j]); for(int i=1;i<=n;i++) res=max(res,f[n][i]); cout<<res<<endl; return 0; } 采药 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e4+10,mod=1e9+7; string s; int n,t,a[N][N],f[N],res,num,ans,m,v[N],w[N]; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>m>>n; for(int i=1;i<=n;i++) cin>>w[i]>>v[i]; for(int i=1;i<=n;i++) for(int j=m;j>=w[i];j--) f[i]=max(f[i],f[i-w[i]]+v[i]); cout<<f[m]<<endl; return 0; } 最大字段和 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; int s[N]; int n,t,a[N],f[N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>m; f[i]=max(m,f[i-1]+m); res=max(res,f[i]); } cout<<res<<endl; return 0; } 装箱问题 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m,w[N]; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>m>>n; for(int i=1;i<=n;i++) cin>>w[i]; for(int i=1;i<=n;i++) for(int j=m;j>=w[i];j--) f[j]=max(f[j],f[j-w[i]]+w[i]); cout<<m-f[m]; return 0; } 疯狂的采药 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m,w[N],v[N]; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>m>>n; for(int i=1;i<=n;i++) cin>>w[i]>>v[i]; for(int i=1;i<=n;i++) for(int j=w[i];j<=m;j++) f[j]=max(f[j],f[j-w[i]]+v[i]); cout<<f[m]; return 0; } 小A点菜 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; f[1]=1; for(int i=1;i<=n;i++) for(int j=m;j>=a[i];j--) f[j]+=f[j-a[i]]; cout<<f[m]<<endl; return 0; } kkksc03考前临时抱佛脚 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; int s[5]; int n,t,a[N],f[N],res,num,ans,m,r,l; bool vis[N]; void dfs(int u,int v) { if(u==s[v]+1){ ans=min(ans,max(l,r)); return; } l+=a[u],dfs(u+1,v),l-=a[u]; r+=a[u],dfs(u+1,v),r-=a[u]; } signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); for(int i=1;i<=4;i++) cin>>s[i]; for(int i=1;i<=4;i++){ ans=0x3f3f3f,l=0,r=0; for(int j=1;j<=s[i];j++) cin>>a[j]; dfs(1,i),res+=ans; } cout<<res<<endl; return 0; } 摆花 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; f[0]=1; for(int i=1;i<=n;i++) for(int j=m;j>=0;j--) for(int k=1;k<=min(a[i],j);k++) f[j]+=f[j-k]&mod; cout<<f[m]; return 0; } #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e4+10,mod=1e6+7; string s; int n,t,a[N],f[N][N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; f[0][0]=1; for(int i=1;i<=n;i++) for(int j=0;j<=m;j++) for(int k=0;k<=min(j,a[i]);k++) f[i][j]=(f[i][j]+f[i-1][j-k])%mod; cout<<f[n][m]; return 0; }
标签:std,cout,int,cin,long,7.22,tie From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17574119.html