poj 2409
来源:互联网 发布:appium python ios 编辑:程序博客网 时间:2024/05/16 19:30
Let it Bead
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4095 Accepted: 2681
Description
"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced.
A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.
A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.
Input
Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.
Output
For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.
Sample Input
1 12 12 25 12 52 66 20 0
Sample Output
123581321
Source
Ulm Local 2000
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <cmath>using namespace std;const int maxn = 40;int ans[maxn][maxn];int c , s;int gcd(int a , int b){if(a%b != 0){return gcd(b , a%b);}return b;}void initial(){memset(ans , 0 , sizeof ans);}int polya(int color ,int beed){double sum = 0;for(int i = 1;i <= beed;i++){sum += pow(color*1.0 ,gcd(beed , i));}if(beed%2 == 0){sum += beed/2*pow(color*1.0 , (beed/2+1));sum += beed/2*pow(color*1.0 , (beed/2));}else{sum += beed*pow(color*1.0 , beed/2+1);}return int(sum/(2*beed));}void computing(){for(int i = 1;i < maxn;i++){for(int j = 1;j < maxn;j++){ans[i][j] = polya(i , j);}}}int main(){initial();computing();while(cin >> c >> s && (c||s)){cout << ans[c][s] << endl;}return 0;}
- poj 2409
- POJ 2409
- POJ 2409
- poj 2409 poj 1286【马克】
- POJ 1286 && POJ 2409 Polya定理
- poj 2409解题报告
- POJ 2409 波利亚原理
- POJ 2409 Polya定理
- poj 2409 polya定理
- poj 2409 简单polya
- poj 2409 polya定理
- poj 2409 Polya
- POJ 2409 let_it_bead
- poj 2409 polya定理
- poj 2409 polya计数
- POJ 2409 ploya定理
- POJ 2409 Polya组合
- poj 2409 polya原理
- memcached的执行流程
- rand()在windows和linux下的异同分析
- java 的*.class文件结构
- NMAP使用实例(六)
- Oracle常用命令——工作记录
- poj 2409
- 数据结构与算法系列-树-二叉树的定义与性质
- hdoj-1002 大数加法
- Androidpn学习与使用6
- Sencha Touch 2学习笔记(一)---环境搭建和开发工具配置
- 定义一个函数,其参数为年、月、日的值,返回这一天为该年的第几天
- discuz收录
- 理解指针
- JQuery练习——伸缩的导航