全部评论
跳柱子 #include<bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
x=0;int f=0;char ch=getchar();
while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar();
while (ch>='0'&& ch<='9') x=x*10+ch-'0',ch=getchar();
return x=f?-x:x;
}
const int N=1e3+10;
int T,n,k,i,j,h[N];
bool dp[N][2];
int main(){
for (read(T);T--;){
read(n),read(k);
for (i=1;i<=n;++i) read(h[i]),dp[i][0]=dp[i][1]=0;
dp[1][0]=1;
for (i=2;i<=n;++i){
for (j=1;j<=i;++j)if(i-j>=1 && i-j<=k){
if (h[j]>=h[i]){
dp[i][0]|=dp[j][0];
dp[i][1]|=dp[j][1];
}
dp[i][1]|=dp[j][0];
}
}
if (dp[n][0] || dp[n][1]) puts("YES");
else puts("NO");
}
return 0;
} 积木 #include<bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
x=0;int f=0;char ch=getchar();
while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar();
while (ch>='0'&& ch<='9') x=x*10+ch-'0',ch=getchar();
return x=f?-x:x;
}
const int N=1e5+10;
int T,n,i;
ll m,h[N];
int main(){
for (read(T);T--;){
read(n),read(m);
for (i=0;i<n;++i) read(h[i]);
bool flag=0;
for (i=0;i<n;++i){
if (h[i]>i) m+=h[i]-i;
else{
if (i-h[i]>m){
flag=1;
break;
}
else m-=i-h[i];
}
}
puts(flag?"NO":"YES");
}
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int k = scanner.nextInt();
int[] heights = new int[n];
for (int j = 0; j < n; j++) {
heights[j] = scanner.nextInt();
}
if (getResult(heights, k)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
public static boolean getResult(int[] heights, int k) {
boolean[][] dp = new boolean[heights.length][2];
dp[0][0] = true;
dp[0][1] = true;
for (int i = 1; i < heights.length; i++) {
for (int j = i - 1; j >= 0 && j >= i - k; j--) {
if (heights[i] <= heights[j]) {
dp[i][0] = true;
if (dp[j][1]) {
dp[i][1] = true;
break;
}
}
}
if (!dp[i][0]) {
for (int j = i - 1; j >= 0 && j >= i - k; j--) {
if (dp[j][1]) {
dp[i][0] = true;
break;
}
}
}
}
return dp[heights.length - 1][0];
}
} 有大佬能帮我看看这个跳柱子的解法哪里有问题吗?我只能AC 10%。
大佬,和相等的怎么解决的,我只过了60
我用的dp做的跳积木。
跳桩子BFS可以a
相关推荐
点赞 评论 收藏
分享
牛客458797590号:你们真信啊?无线是大部门,下分三四级小部门,累不累分组啊
点赞 评论 收藏
分享