#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const double eps=1e7-8;
const int INF=0x3f3f3f3f;
const int maxn=1e5+5;
const int maxm=1e6+5;
ll n,m,f[maxn],w[maxn],v[maxn];
int main(int argc, char const *argv[]){
std::ios::sync_with_stdio(false);
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=m;j>=w[i];--j){
f[j]=max(f[j-w[i]]+v[i],f[j]);
}
}
cout<<f[m];
return 0;
}
]#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int maxn=1e5+5;
const int maxm=1e6+5;
int n,m,v[105],w[105],dp[maxm],Max;
int main(int argc,char const *argv[]){
std::ios::sync_with_stdio(false);
cin>>n>>m;
Max=n*1000;
for(int i=1;i<=n;++i)cin>>w[i]>>v[i];
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
for(int i=1;i<=n;++i){
for(int j=Max;j>=v[i];--j){
dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
}
}
for(int i=Max;i;--i){
if(dp[i]<=m){
cout<<i;
return 0;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n,d[110][3],m[110];
int main()
{ memset(d,127,sizeof(d));
cin>>n;
for(int i=1;i<=n;i++){
cin>>m[i];
}
for(int i=0;i<3;i++){
d[0][i]=0;
}
for(int j=1;j<=n;j++){
d[j][0]=min(min(d[j][0],d[j-1][0]),min(d[j-1][1],d[j-1][2]))+1;
if(m[j]==1||m[j]==3){
d[j][1]=min(d[j-1][0],d[j-1][2]);
}
if(m[j]==2||m[j]==3){
d[j][2]=min(d[j-1][0],d[j-1][1]);
}
}
cout<<min(d[n][0],min(d[n][1],d[n][2]));
}
#include <bits/stdc++.h>
using namespace std;
int h, w, dp[1005][1005];
char c[1005][1005];
int main()
{
cin >> h >> w;
for(int i = 1; i <= h; i ++)
{
for(int j = 1; j <= w; j ++)
{
cin >> c[i][j];
}
}
dp[1][1] = 1;
for(int i = 1; i <= h; i ++)
{
for(int j = 1; j <= w; j ++)
{
if(c[i][j] == '#' || (i == 1 && j == 1)) continue;
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % (1000000007);
}
}
cout << dp[h][w] << endl;
return 0;
}
躲猫猫对面
最新推荐文章于 2024-01-05 22:30:09 发布