D. Add One -动态规划

题目大意:数字的每位每次加一

动态规划预处理:

#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define fep(i,a,b) for(int i=b;i>=a;--i)
#define mem(x,y) memset(x,y,sizeof(x))
#define inf 2147483647
const int mod = 1e9+7;
const int N = 2e5;
using namespace std;

ll dp[N+10];


void solve()
{
    int n, m;
    cin >> n >> m;
	ll ans=0;
	while(n)
	{
		int x=10-n%10;
		if(m<x) ans=(ans+1)%mod;
		else ans=(ans+dp[m-x])%mod;
		n /= 10;
	}
	printf("%lld\n",ans);
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    for (int i = 0; i <= 8; i++) dp[i] = 2;
    dp[9] = 3;
    for (int i = 10; i <= 200010; i++)
    {
        dp[i] = (dp[i - 9] + dp[i - 10]) % mod;
    }

    int T; cin >> T;
    while (T--)
        solve();
    return 0;
}
#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define fep(i,a,b) for(int i=b;i>=a;--i)
#define mem(x,y) memset(x,y,sizeof(x))
#define inf 2147483647
const int mod = 1e9+7;
const int N = 2e5;
using namespace std;

vector<int>v;
ll sum[N+10], dp[N+10][15];


void fun()
{
	dp[0][1]=1;dp[0][0]=1;sum[0]=2;
	for(int i=1;i<N;++i)
	for(int j=0;j<=9;++j)
	{
		if(j) dp[i][j]=dp[i-1][j-1];
		if(j==0||j==1) dp[i][j]=(dp[i][j]+dp[i-1][9])%mod;
		sum[i]=(sum[i]+dp[i][j])%mod;
	}	
} 

void solve()
{
    int n, m;
	scanf("%d%d",&n,&m);
	ll ans=0;
	while(n>0)
	{
		int x=10-n%10;
		if(m<x) ans=(ans+1)%mod;
		else ans=(ans+sum[m-x])%mod;
		n /= 10;
	}
	printf("%lld\n",ans);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    fun();
    int T; 
    scanf("%d", &T);
    
    while (T--)
        solve();
    return 0;
}
没有GPU,优化程序class point_cloud_generator(): def init(self, rgb_file, depth_file, save_ply, camera_intrinsics=[312.486, 243.928, 382.363, 382.363]): self.rgb_file = rgb_file self.depth_file = depth_file self.save_ply = save_ply self.rgb = cv2.imread(rgb_file) self.depth = cv2.imread(self.depth_file, -1) print("your depth image shape is:", self.depth.shape) self.width = self.rgb.shape[1] self.height = self.rgb.shape[0] self.camera_intrinsics = camera_intrinsics self.depth_scale = 1000 def compute(self): t1 = time.time() depth = np.asarray(self.depth, dtype=np.uint16).T self.Z = depth / self.depth_scale fx, fy, cx, cy = self.camera_intrinsics X = np.zeros((self.width, self.height)) Y = np.zeros((self.width, self.height)) for i in range(self.width): X[i, :] = np.full(X.shape[1], i) self.X = ((X - cx / 2) * self.Z) / fx for i in range(self.height): Y[:, i] = np.full(Y.shape[0], i) self.Y = ((Y - cy / 2) * self.Z) / fy data_ply = np.zeros((6, self.width * self.height)) data_ply[0] = self.X.T.reshape(-1)[:self.width * self.height] data_ply[1] = -self.Y.T.reshape(-1)[:self.width * self.height] data_ply[2] = -self.Z.T.reshape(-1)[:self.width * self.height] img = np.array(self.rgb, dtype=np.uint8) data_ply[3] = img[:, :, 0:1].reshape(-1)[:self.width * self.height] data_ply[4] = img[:, :, 1:2].reshape(-1)[:self.width * self.height] data_ply[5] = img[:, :, 2:3].reshape(-1)[:self.width * self.height] self.data_ply = data_ply t2 = time.time() print('calcualte 3d point cloud Done.', t2 - t1) def write_ply(self): start = time.time() float_formatter = lambda x: "%.4f" % x points = [] for i in self.data_ply
最新发布
05-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值