zoukankan      html  css  js  c++  java
  • codeforces 758 D

    n进制

    n进制数

    求一个最小的十进制数上面那个数可以变成

    一眼看到就是不会   看题解 

    是区间DP

    dp[i] 从前处理到i位的最小的数

    dp[i]=min(dp[i],dp[i-1]*n+now);

    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    #include<math.h>
    #include<set>
    #include<string>
    
    using namespace std;
    typedef long long LL;
    
    #define inf  2000000000000000000
    #define MAXN 65
    char str[MAXN];
    LL   dp[MAXN];
    
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            scanf("%s",str+1);
            int len=strlen(str+1);
            for(int i=1;i<=len;i++)
                dp[i]=inf;
            dp[0]=0;
            for(int i=1;i<=len;i++)
            {
                LL now=0;
                for(int j=i;j<=len;j++)
                {
                    now=now*10+str[j]-'0';
                    if(str[i]=='0'&&j>i)  //不能有00  01...  
                        break;
                    if(now>=n)
                        break;
                    if(1.0*dp[i-1]*n+now>2e18) //这个数<2e18  题目写了 
                        continue;
                    dp[j]=min(dp[j],dp[i-1]*n+now);
                }
            }
            printf("%lld
    ",dp[len]);
        }
        return 0;
    }
  • 相关阅读:
    java9新特性-9-语法改进:try语句
    10.04 FZSZ模拟Day1 总结
    10.03模拟总结
    HNOI2012 永无乡
    ZJOI2007 报表统计
    HNOI2004 宠物收养场
    HNOI2002 营业额统计
    Splay 区间反转
    Splay基本操作
    HEOI2016 树
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6429014.html
Copyright © 2011-2022 走看看