ArabellaCPC 2019 J. Thanos Power 动态规划

博客围绕给定数N,探讨其最少通过多少次操作从初值0得到,等价于N通过多少次操作得到0。从高位往低位看,对于每一位数x有两种变0方法,还给出了动态规划数组d[i][0]和d[i][1]的状态转移方程。

J. Thanos Power

题意:给你一个数N,让你求它最少通过多少次操作得到的。 初值为0,每次操作只能增加10^{x},x >= 0;

0最少通过多少次操作得到的N,等价于N通过多少次操作得到的0

从高位往低位看,,,

对于每一位上的数x,我有两种方法让它变成0,

  1. 一直加 1,加到10后进位,操作数10-x
  2. 一直减 1,减到 0, 操作数 x

d[i][0] 表示第i位一直执行加 1 ,最后变成0的操作次数。

d[i][1] 表示第i位一直执行减 1 ,最后变成0的操作次数。

d[i][0]=10-x + min ( d[i-1][0]-1 ,  d[i-1][1]+1 );因为执行完后会进1,所以d[i-1][0] 需要 -1,d[i-1][1] 需要 +1;

d[i][1] = x  +  min( d[i-1][0] ,  d[i-1][1] );

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;

char str[N];
int d[N][2];
int main(){
	scanf("%s",str);
	d[0][0] = 10 - (str[0] - '0') + 1;
	d[0][1] = str[0] - '0' ;
	int l = strlen(str);
	
	for(int i = 1; i < l; i++){
		d[i][0] = 10 - (str[i] - '0') + min(d[i-1][0]-1, d[i-1][1]+1);
		d[i][1] = str[i] - '0' + min(d[i-1][0], d[i-1][1]);
	}
	printf("%d\n",min(d[l-1][0], d[l-1][1]));
	return 0;
}

 

com.tongweb.deploy.interfaces.DeployException: com.tongweb.deploy.interfaces.DeployException: com.tongweb.web.thanos.startup.DeployInnerWebtierException: com.tongweb.web.thanos.startup.DeployInnerWebtierException: java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWebtierInnerPhaserootcause is java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWebtierInnerPhaserootcause is com.tongweb.web.thanos.startup.DeployInnerWebtierException: java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWebtierInnerPhaserootcause is java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWrapperPhase-------报这个错了
最新发布
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值