Super Jumping! Jumping! Jumping!(dp)

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.

The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.

Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.

Output
For each case, print the maximum according to rules, and one line one case.

Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0

Sample Output
4
10
3

这道题其实就是求上升子序列最大和,虽然看懂了需要用dp来写但是我还处于动态规划学习中…写出来的总感觉不算是一个dp
看来还是需要增强对dp的理解

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int i,j,n,m,s,dp[3][1005];
	while(~scanf("%d",&n) && n)
	{
		memset(dp,0,sizeof(dp));
		s=0;
		for(i=1;i<=n;i++)cin>>dp[1][i];
		dp[2][1]=dp[1][1];
		for(j=2;j<=n;j++)
		{
			m=0;
			for(i=1;i<j;i++)
			{
				if(dp[1][i]<dp[1][j] && m<dp[2][i])m=dp[2][i];
			}
			dp[2][j]=dp[1][j]+m;
			if(dp[2][j]>s)s=dp[2][j];
		}
		cout<<s<<endl;
	}
	return 0;
}
好的,以下是一个简单的 Android Studio 跳一跳游戏示例: 1. 打开 Android Studio,创建一个新项目(New Project) 2. 命名项目为 "JumpGame" 3. 选择要使用的语言(Java 或 Kotlin) 4. 选择目标设备版本 5. 选择空白活动(Empty Activity) 6. 命名活动为 "GameActivity" 7. 在 res/layout 目录下创建一个名为 "activity_game.xml" 的布局文件,添加以下代码: ```xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary"> <Button android:id="@+id/button" android:layout_width="100dp" android:layout_height="100dp" android:layout_centerInParent="true" android:background="@drawable/circle" /> </RelativeLayout> ``` 这个布局文件中包含一个居中的 Button,用于作为跳板。 8. 在 res/drawable 目录下创建一个名为 "circle.xml" 的矢量图文件,添加以下代码: ```xml <?xml version="1.0" encoding="UTF-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="100dp" android:height="100dp" android:viewportWidth="100" android:viewportHeight="100"> <path android:fillColor="#ffffff" android:pathData="M50,0 C22.386,0 0,22.386 0,50 C0,77.614 22.386,100 50,100 C77.614,100 100,77.614 100,50 C100,22.386 77.614,0 50,0 Z" /> </vector> ``` 这个矢量图文件定义了一个白色的圆形。 9. 在 GameActivity 类中添加以下代码: ```java public class GameActivity extends AppCompatActivity { private Button button; // 跳板 private int score = 0; // 得分 private boolean isJumping = false; // 是否在跳跃 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game); button = findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isJumping) { jump(); } } }); } private void jump() { isJumping = true; // 计算跳跃高度 ValueAnimator animator = ValueAnimator.ofInt(0, 300); animator.setDuration(1000); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); button.setTranslationY(-value); } }); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { // 动画开始时 } @Override public void onAnimationEnd(Animator animation) { // 动画结束时 isJumping = false; score++; Toast.makeText(GameActivity.this, "得分:" + score, Toast.LENGTH_SHORT).show(); } @Override public void onAnimationCancel(Animator animation) { // 动画取消时 } @Override public void onAnimationRepeat(Animator animation) { // 动画重复时 } }); animator.start(); } } ``` 这段代码定义了一个 GameActivity 类,其中包含一个跳板、得分和跳跃动画。当用户点击跳板时,将会触发跳跃动画,并更新得分。 10. 运行程序,在设备上点击跳板,即可看到跳跃动画和得分更新。 这是一个简单的跳一跳游戏示例,你可以根据自己的需求定制化该游戏。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值