思维好重要。。

对于n+m == k , 当n == m || abs(n-m) == 1 时n*m取得最大值。

设 s = x*(l-x),s = lx-x^2.其导函数为 s‘ = -1/2x + l。显然 s 在 x == l/2处取得最大值。

则对于k分解成若干个数,则最后有若干个3和若干个2。

又有,三个2换成两个3。和不变积增大。

所以最后最多之会有两个2,剩下的由3组成。

则题目变成了 求3^m。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <map> #pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-8)
#define LL long long
#define ULL unsigned long long int
#define _LL __int64
#define _INF 0x3f3f3f3f
#define Mod 1000000007
#define LM(a,b) (((ULL)(a))<<(b))
#define RM(a,b) (((ULL)(a))>>(b)) using namespace std; map<int,int> Max; int Cal(int x,int n)
{
if(n == 1)
return x;
if(n == 2)
return x*x; if(Max.find(n) == Max.end())
{
if(n&1)
{
int t1 = Cal(x,n/2);
int t2 = Cal(x,n/2 + 1); t1 = t1*t2;
t1 %= 2009; Max.insert(pair<int,int>(n,t1));
return t1; }
else
{
int t1 = Cal(x,n/2); t1 = t1*t1;
t1 %= 2009;
Max.insert(pair<int,int>(n,t1));
return t1;
}
}
return Max[n];
} int main()
{
int n; while(scanf("%d",&n) != EOF)
{
if(n <= 4)
{
printf("%d\n",n);
}
else
{
if(n%3 == 0)
{
printf("%d\n",Cal(3,n/3)%2009);
}
else if(n%3 == 2)
{
printf("%d\n",(Cal(3,n/3)*2)%2009);
}
else
{
printf("%d\n",(Cal(3,n/3 - 1)*4)%2009);
}
}
}
return 0;
}

最新文章

  1. Windows Azure Table storage 之 动态Table类 DynamicTableEntity
  2. python import 模块异常问题
  3. Install wget for mac
  4. 21. Merge Two Sorted Lists
  5. STL 简介,标准模板库
  6. bzoj1064
  7. Halcon C++混合编程学习之Qt 实现检测焊接点
  8. redhat6.5 配置使用centos的yum源
  9. Bzoj 3289: Mato的文件管理 莫队,树状数组,逆序对,离散化,分块
  10. JavaScript HTML DOM EventListener
  11. linux处理闰秒
  12. 论深度优先(DFS)和广度优先搜索(BF)的优点及不足(更新ing)
  13. idea控制台输出乱码
  14. Java多线程synchronized关键字
  15. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩
  16. 结构数组新发现之直接初始化《leetcode-合并区间》
  17. python mysql中文乱码
  18. 函数和常用模块【day05】:迭代器(六)
  19. 编译openssl失败(SLES11.3), undefined reference to `OPENSSL_cpuid_setup&#39;
  20. BZOJ1855 股票交易 单调队列优化 DP

热门文章

  1. Codeforces434D 网络流
  2. 页面出现AXURE RP EXTENSION,怎么办?
  3. 关于网易云音乐爬虫的api接口?
  4. BZOJ 3637: Query on a tree VI LCT_维护子树信息_点权转边权_好题
  5. v2.0版本小程序开发心得(代码之外)
  6. iOS开发——导入c文件引起的 Unknown type name &#39;NSString&#39; 错误
  7. Mooc--五子棋(js)小结
  8. 【Codeforces Round #421 (Div. 2) B】Mister B and Angle in Polygon
  9. win32下实现透明窗体
  10. Android——bootchart