洛谷P2871 [SACO07DEC]手链Charm Bracelet+P2639 [USACO09OCT]Bessie的体重问题Bessie's We…

01背包问题
分为二维还是一维模板不同
此题二维会炸要用一维存储的使其通过
初学
一定要学会看题目范围 像zzc说的范围过大就直接暴力

洛谷P2871 [SACO07DEC]手链Charm Bracelet
https://www.luogu.org/problemnew/show/P2871
#include<stdio.h>

#include<bits/stdc++.h>

const int maxn=19999;
//int a[maxn][maxn];
using namespace std;
int v[maxn];///价值
int w[maxn];///容量
int V[maxn][maxn];
int B[maxn];
int FindMaxBetter(int number,int capacity)//优化空间后的动态规划
{
int i,j;
for(i=1;i<=number;i++)
{
for(j=capacity;j>=w[i];j–)
{
if(B[j]<=B[j-w[i]]+v[i])//二维变一维
{
B[j]=B[j-w[i]]+v[i];
}
//B[j]=max(B[j],B[j-w[i]]+v[i]); ///二维变一维的另一种方法
}
}
return B[capacity];
}
int main()
{
int n,m;
cin>>n>>m;
for(int j=1; j<=n; j++)///划重点 一定要重数组下标为1开始 ///WA了两次看完题解才知道是读入错误
{
cin>>w[j]>>v[j];
}
int c=FindMaxBetter(n,m);
cout<<c<<endl;
}
/
P2639 [USACO09OCT]Bessie的体重问题Bessie’s We…
https://www.luogu.org/problemnew/show/P2639
一样的01背包问题知识需要简单的更改一下数据多考虑几分钟就可以搞出来 但是此题需要注意范围45000
#include<stdio.h>

#include<bits/stdc++.h>
const int maxn=59999;
//int a[maxn][maxn];
using namespace std;
int v[maxn];///价值
int w[maxn];///容量
//int V[maxn][maxn];
int B[maxn];
int FindMaxBetter(int number,int capacity)//优化空间后的动态规划
{
int i,j;
for(i=1;i<=number;i++)
{
for(j=capacity;j>=w[i];j–)
{
if(B[j]<=B[j-w[i]]+v[i])//二维变一维
{
B[j]=B[j-w[i]]+v[i];
}
//B[j]=max(B[j],B[j-w[i]]+v[i]);
}
}
return B[capacity];
}
int main()
{
int n,m;
cin>>n>>m;

for(int j=1; j<=m; j++)///不同之处 将重量和价值使其相等就ok
{
cin>>w[j];
v[j]=w[j];
}

int c=FindMaxBetter(m,n);
cout<<c<<endl;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用中文总结以下内容: A number of experimental and numerical investigations have been conducted to study the MBPP stack and wavy flow field characteristics with various designs [10,11]. T. Chu et al. conducted the durability test of a 10-kW MBPP fuel cell stack containing 30 cells under dynamic driving cycles and analyzed the performance degradation mechanism [12]. X. Li et al. studied the deformation behavior of the wavy flow channels with thin metallic sheet of 316 stainless steel from both experimental and simulation aspects [13]. J. Owejan et al. designed a PEMFC stack with anode straight flow channels and cathode wavy flow channels and studied the in situ water distributions with neutron radiograph [14]. T. Tsukamoto et al. simulated a full-scale MBPP fuel cell stack of 300 cm2 active area at high current densities and used the 3D model to analyze the in-plane and through-plane parameter distributions [15]. G. Zhang et al. developed a two-fluid 3D model of PEMFC to study the multi-phase and convection effects of wave-like flow channels which are symmetric between anode and cathode sides [16]. S. Saco et al. studied the scaled up PEMFC numerically and compared straight parallel, serpentine zig-zag and straight zig-zag flow channels cell with zig-zag flow field with a transient 3D numerical model to analyze the subfreezing temperature cold start operations [18]. P. Dong et al. introduced discontinuous S-shaped and crescent ribs into flow channels based on the concept of wavy flow field for optimized design and improved energy performance [19]. I. Anyanwu et al. investigated the two-phase flow in sinusoidal channel of different geometric configurations for PEMFC and analyzed the effects of key dimensions on the droplet removal in the flow channel [20]. Y. Peng et al. simulated 5-cell stacks with commercialized flow field designs, including Ballard-like straight flow field, Honda-like wavy flow field and Toyota-like 3D mesh flow field, to investigate their thermal management performance [21]. To note, the terms such as sinusoidal, zig-zag, wave-like and Sshaped flow channels in the aforementioned literatures are similar to the so called wavy flow channels in this paper with identical channel height for the entire flow field. The through-plane constructed wavy flow channels with periodically varied channel heights are beyond the scope of this paper [22,23].
02-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值