惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
A
Arctic Wolf
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Troy Hunt's Blog
小众软件
小众软件
L
LangChain Blog
Schneier on Security
Schneier on Security
D
DataBreaches.Net
爱范儿
爱范儿
P
Proofpoint News Feed
博客园 - 聂微东
M
MIT News - Artificial intelligence
Hacker News: Ask HN
Hacker News: Ask HN
T
Tailwind CSS Blog
Vercel News
Vercel News
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
月光博客
月光博客
Spread Privacy
Spread Privacy
C
Cisco Blogs
S
Securelist
量子位
S
Security @ Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tenable Blog
WordPress大学
WordPress大学
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
C
Cybersecurity and Infrastructure Security Agency CISA
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
Help Net Security
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
B
Blog RSS Feed
博客园_首页
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

博客园 - saintqdd

hdu 1102 pku 2421 解题报告 pku 2777 Count Color 解体报告 石子合并问题 nkoj1139和乘积最大那题一样. A Tour in Loquat Orchard (FZU 2007 ICPC Qualification Round I tzw) 最大黑区域 滑雪 一道经典题,humble number 今天碰到了一个很诡异的题,Alphacode (zoj 2202) 这两天经常碰到dp题,就写了一个0-1背包 实训以来,到这里的次数少了! Smith Number POJ强烈推荐50题 JOJ 2391 words POJ 1014 三十分钟掌握STL STL学习小记 POJ1006,中国剩余定理 POJ1003,简单题
郁闷,乘积最大那题WA原来只是因为我用了pow函数引起的!
saintqdd · 2007-08-08 · via 博客园 - saintqdd

大家都知道pow函数是返回double类型的,但有时我们希望求整数的次方用它,只不过强制转换为int or __int64,虽然很多时候这样是可行的,但是也有特殊情况,比如我这次遇到的。

Description

设有一个长度为N的数字串(N ≤ 15),我们要求使用K个乘号,将其分成K+1份。

找出一种分法,使得这K+1部分的乘积为最大。
例如:K = 1,数字串为312时会有以下两种分法:
1) 3*12 = 36
2) 31*2 = 62
这时,符合题目要求的结果是:62

my code:

#include<iostream>
#include<string.h>
__int64 k;
char arr[15];
__int64 get_v(__int64 s,__int64 e){
    __int64 i,v=arr[e]-48,t=1;
    for(i=e-1;i>=s;i--){
        t*=10;
        v+=(arr[i]-48)*t;
    }
    return v;
}
__int64 find(__int64 s,__int64 e,__int64 kt){
    if(kt==0)
        return get_v(s,e);
    __int64 i,m=0,t;
    for(i=s;i<=e-kt;i++){        
            t=find(i+1,e,kt-1)*get_v(s,i);
            if(t>m)
                m=t;        
    }
    return m;
}
int main(){
    while(scanf("%I64d",&k)!=-1){
        scanf("%s",arr);
        __int64 l=(__int64)strlen(arr),s=0,kt=k,i,t;
        if(k>0){
                for(i=0;i<=l-1-kt;i++){                    
                        t=find(i+1,l-1,kt-1)*get_v(0,i);
                        if(t>s)
                            s=t;                    
                }
        }
        else
            s=get_v(0,l-1);
        printf("%I64d\n",s);
    }
}