- 乘积最大
- 2015-08-30 16:29:35 @
记录信息
评测状态 Wrong Answer
题目 P1347 乘积最大
递交时间 2015-08-30 16:16:02
代码语言 C++
评测机 VijosEx
消耗时间 2 ms
消耗内存 852 KiB
评测时间 2015-08-30 16:16:03
评测结果
编译成功
foo.cpp: In function 'int main()':
foo.cpp:34:27: warning: unknown conversion type character 'l' in format [-Wformat=]
printf("%lld",dp[1][n][k]);
^
foo.cpp:34:27: warning: too many arguments for format [-Wformat-extra-args]
测试数据 #0: WrongAnswer, time = 0 ms, mem = 852 KiB, score = 0
测试数据 #1: Accepted, time = 0 ms, mem = 852 KiB, score = 27
测试数据 #2: WrongAnswer, time = 2 ms, mem = 852 KiB, score = 0
测试数据 #3: Accepted, time = 0 ms, mem = 852 KiB, score = 27
WrongAnswer, time = 2 ms, mem = 852 KiB, score = 54
代码
#include <iostream>
#include <stdio.h>
using namespace std;
long long num[45][45],dp[45][45][20];
char s[150];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
scanf("%s",s);
for(int j=1;j<=n;j++)
dp[j][j][0]=s[j-1]-'0';
for(int dist=0;dist<n;dist++)
for(int i=1;i+dist<=n;i++)
num[i][i+dist]=num[i][dist+i-1]*10+s[dist+i-1]-'0';
for(int i=1;i<=k;i++)
{
for(int j=i-1;j<n;j++)
{
for(int o=1;o+j<=n;o++)
{
for(int pos=o;pos<j+o;pos++)
{
dp[o][j+o][i]=max(dp[o][o+j][i],num[o][pos]*dp[pos+1][o+j][i-1]);
}
for(int pos=o;pos<j+o;pos++)
{
dp[o][j+o][i]=max(dp[o][o+j][i],dp[o][pos][i-1]*num[pos+1][o+j]);
}
}
}
}
printf("%lld",dp[1][n][k]);
}
1 条评论
-
TenderRun LV 10 @ 2015-08-31 09:10:46
原来赋初值赋错了。。。
无语了记录信息
评测状态 Accepted
题目 P1347 乘积最大
递交时间 2015-08-31 09:09:04
代码语言 C++
评测机 VijosEx
消耗时间 38 ms
消耗内存 852 KiB
评测时间 2015-08-31 09:09:05
评测结果
编译成功foo.cpp: In function 'int main()':
foo.cpp:35:30: warning: unknown conversion type character 'l' in format [-Wformat=]
printf("%lld",dp[1][n][k]);
^
foo.cpp:35:30: warning: too many arguments for format [-Wformat-extra-args]
测试数据 #0: Accepted, time = 1 ms, mem = 852 KiB, score = 23
测试数据 #1: Accepted, time = 0 ms, mem = 852 KiB, score = 27
测试数据 #2: Accepted, time = 22 ms, mem = 848 KiB, score = 23
测试数据 #3: Accepted, time = 15 ms, mem = 852 KiB, score = 27
Accepted, time = 38 ms, mem = 852 KiB, score = 100
代码
#include <iostream>
#include <stdio.h>
using namespace std;
long long num[45][45],dp[45][45][20];
char s[150];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
scanf("%s",s);for(int dist=0;dist<n;dist++)
for(int i=1;i+dist<=n;i++)
num[i][i+dist]=num[i][dist+i-1]*10+s[dist+i-1]-'0';
for(int i=0;i<n;i++)
for(int j=1;j+i<=n;j++)
dp[j][i+j][0]=num[j][i+j];
for(int i=1;i<=k;i++)
{
for(int j=i-1;j<n;j++)
{
for(int o=1;o+j<=n;o++)
{
for(int pos=o;pos<j+o;pos++)
{
dp[o][j+o][i]=max(dp[o][o+j][i],num[o][pos]*dp[pos+1][o+j][i-1]);
}
for(int pos=o;pos<j+o;pos++)
{
dp[o][j+o][i]=max(dp[o][o+j][i],dp[o][pos][i-1]*num[pos+1][o+j]);
}
}
}
}
printf("%lld",dp[1][n][k]);
}
- 1