多项式计算,有点像母函数,注意最后要判断最高次项是否为0。

#include <cstdio>
#include <cstring>
using namespace std; #define MAX_NUM 105 int a_num, b_num;
int a[MAX_NUM], b[MAX_NUM];
int c[MAX_NUM * MAX_NUM];
int poly[][MAX_NUM * MAX_NUM];
int poly_num; void input()
{
scanf("%d%d", &a_num, &b_num);
for (int i = ; i <= a_num; i++)
scanf("%d", &a[i]);
for (int i = ; i <= b_num; i++)
scanf("%d", &b[i]);
} void add_c(int poly[], int a)
{
for (int i = ; i <= poly_num; i++)
c[i] += a * poly[i];
} void add_poly(int last[], int next[])
{
memset(next, , sizeof(int) * MAX_NUM * MAX_NUM);
for (int i = ; i <= b_num; i++)
{
for (int j = ; j <= poly_num; j++)
next[i + j] += b[i] * last[j];
}
poly_num += b_num;
} void work()
{
memset(c, , sizeof(c));
for (int i = ; i <= b_num; i++)
{
poly[][i] = b[i];
}
poly_num = b_num;
c[] = a[];
add_c(poly[], a[]);
for (int i = ; i <= a_num; i++)
{
add_poly(poly[(i - ) & ], poly[i & ]);
add_c(poly[i & ], a[i]);
}
while (c[poly_num] == )
poly_num--;
printf("%d", c[]);
for (int i = ; i <= poly_num; i++)
printf(" %d", c[i]);
puts("");
} int main()
{
int case_num;
scanf("%d", &case_num);
for (int i = ; i < case_num; i++)
{
input();
work();
}
}

poj1996的更多相关文章

随机推荐

  1. vmEsxi一些使用

    打开esxi的shell:在故障检查选项中 回车,打开shell ALT+F1进入esxi的shell ALT+F2返回 精简置备--用多少占多少,上限为设置的磁盘大小 虚机扩容:1.原本的扩容2.添 ...

  2. final 140字评论II

    1.约跑app: 从性能上讲,着重修改了其他组找出的bug,性能上有了很大的提高,增强了实用性. 从功能上讲,该app可以增加用户之间的互动性,有较多的客户群,适合人群不限于青少年和成年人. 从UI上 ...

  3. PAT 甲级 1085 Perfect Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...

  4. Docker(八)-Docker创建Nginx容器

    获取Nginx镜像 最简单的方法就是通过 docker pull nginx 命令来创建 Nginx容器. $ sudo docker pull nginx 或者: $ sudo docker pul ...

  5. SpringBoot 6.SpringBoot使用 Log4j2 实现日志输出

    一.添加 Log4j2 的依赖 <!-- 引入 log4j2 必须排除 logging --> <dependency> <groupId>org.springfr ...

  6. TP3.2加载外部PHPexcel类,实现导入和导出

    TP3.2加载外部PHPexcel类,实现导入和导出 导入: 1.将下载好的PHPexcel文件放到libray/Org/Uti/文件夹下,将PHPEXCEL.PHP改为PHPEXCEL.class. ...

  7. 怎样实现在DBGrid中双击选择整行,并且可以多选?谢谢!!

    DBGrid1->Options里有个dgMultiSelect,把它设为true就能多选了 先设置DBGrid1->options中dgRowSelect = true, dgMulti ...

  8. UVa 10305 - Ordering Tasks (拓扑排序裸题)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  9. 【BZOJ1047】[HAOI2007]理想的正方形(单调队列,动态规划)

    [BZOJ1047][HAOI2007]理想的正方形(单调队列,动态规划) 题面 BZOJ 洛谷 题解 直接一个单调队列维护一下没给点和它前面的\(n\)个位置的最大值,再用一次单调队列维护连续\(n ...

  10. DP(动态规划)

    http://www.hawstein.com/posts/dp-novice-to-advanced.html https://www.topcoder.com/community/data-sci ...