DP for bombs

86 篇文章 0 订阅
13 篇文章 0 订阅
There are n bombs in a big circle,and each bomb has a value and a 'effect range'.If you detonated a bomb,you will get this bomb's value,but a bomb can have effect on the neighbors which the distance(difference between index) between them is smaller than the 'effect range'.It's say that the neighbor bomb will be destoryed and you could not get their values. 
You will given each bomb's value and the 'effect range',and you need calculate the max value you can get. 
eg. n=3 index 0's bomb' v is 2,range is 0(will not effect others).and v[1]=1,r[1]=1,v[2]=3,r[2]=1; 
this case's max value is 5.(detonate the 0's and than the 2's). 

HELP ME. 

ps: It's a interval DP.

-------------------------------------------------------------------------------------------------------------------------------

Let dp[i][j] be the max value from ith and jth bomb on the circle, forcing i no greater than j. 
Actually by denoting any kth (i <= k and k <= j) bomb, we got a precisely sub problem with smaller size, such that: 
dp[i][j] = Max{ dp[i][bkd] + v[i] + dp[fwd][j] } , where bkd and fwd is by denoting kth bomb, the backward and foward range that not get effected. 

Note this is a circle, sequence does matter, so dp[i][j] assumes from i to j, there are bombs, but from j to i, no bombs.

public class BombGame {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BombGame bg = new BombGame();
		System.out.println(bg.maxValue(new int[] {1, 3, 2}, new int[] {1, 1, 0}));
	}

	private int[] v;
	private int[] r;
	private int length;
	private int[][] dp;

	public int maxValue(int[] v, int[] r) {
		this.v = v;
		this.r = r;
		this.length = v.length;
		this.dp = new int[length][length];
		for(int i = 0; i < length; i++) {
			dp[i][i] = v[i];
		}
		return maxValueInternal(0, length - 1);
	}

	private int maxValueInternal(int start, int end) {
		if(start > end) return 0;
		if (start == end || dp[start][end] != 0)
			return dp[start][end];
		
		for (int i = start; i <= end; i++) {
			// denote i
			int fwd = i + r[i] + 1;
			int bkd = i - r[i] - 1;
			//this is a little tricky, as we have to consider 
			//when the range is very big, it destroy the end
			//bomb, thus changing the end range
			int end_ = (bkd + length) % length;
			end_ = end_ < end ? end_ : end;
			
			dp[start][end] = Math.max(dp[start][end], 
					maxValueInternal(start, bkd) + v[i] + maxValueInternal(fwd, end_));
		}
		return dp[start][end];
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity Bombs VFX是Unity VFX中的一个效果,用于创建爆炸效果。Unity VFX(Visual Effect Graph)是一个用于创建高质量视觉效果的工具。它可以在Unity游戏引擎中实现各种复杂的粒子和效果。 要使用Unity Bombs VFX,您需要了解Unity VFX的基本知识和使用环境。首先,确保您的Unity版本是2019.4.39,并且已经安装了Visual Effect Graph 7.7.1版本。 对于Unity VFX的学习和使用过程,您可以参考官方文档。官方文档提供了详细的教程和示例,帮助您了解VFX的工作原理和使用方法。 相比于传统的粒子系统(如Particle System),Unity VFX具有更强大的性能和功能。它可以处理几十万级别的粒子数量,并实现更夸张和细腻的效果。与Particle System不同的是,Unity VFX对GPU的依赖性较强,因为它使用了Compute Shader来实现效果。 因此,如果您想创建爆炸效果,您可以使用Unity Bombs VFX来实现。您可以参考官方文档中关于Unity Bombs VFX的说明和示例,以了解如何使用和调整该效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Unity VFX学习系列 —— 了解VFX](https://blog.csdn.net/qq_27050589/article/details/127206555)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值