poj 2409、1286 Let it Bead
2013-07-19 10:15
225 查看
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.
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
View Code
poj2409 和poj1286这两个题目意思差不多,解法也是一样。
两个题目考察的是polya计数法,具体去看黑书,其实我也没怎么弄明白,有些地方也还是没搞懂,就拿翻转对称来说,当s为偶数的时候,为什么会是那样的表达式,确实有疑问,不过现在也只能先练熟模版,遇到类似的题目可以有办法解决。
"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.
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
#include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; __int64 num[33]; int c,s; void init() { num[0]=1; for(int i=1;i<=s;i++) { num[i]=num[i-1]*c; } return; } int gcd(int a,int b) { return b?gcd(b,a%b):a; } int main() { while(~scanf("%d%d",&c,&s)) { if(c==0 && s==0) { break; } init(); __int64 ans=0; for(int i=1;i<=s;i++) { ans+=num[gcd(i,s)]; } if(s%2) { ans+=s*num[(s+1)/2]; } else { ans+=s/2*(num[s/2]+num[s/2+1]); } printf("%I64d\n",ans/(2*s)); } return 0; }
View Code
poj2409 和poj1286这两个题目意思差不多,解法也是一样。
两个题目考察的是polya计数法,具体去看黑书,其实我也没怎么弄明白,有些地方也还是没搞懂,就拿翻转对称来说,当s为偶数的时候,为什么会是那样的表达式,确实有疑问,不过现在也只能先练熟模版,遇到类似的题目可以有办法解决。
相关文章推荐
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
- NYOJ 280 LK的项链 &&POJ 2409 Let it Bead(polya 定理)
- POJ 2409 Let it Bead
- poj 2409 Let it Bead(polya)
- POJ 2409 let_it_bead
- POJ 2409 Let it Bead(polay计数)
- POJ 2409 Let it Bead 已翻译
- poj2409 Let it Bead(polya)
- POJ 2409 Let it Bead Pólya定理
- POJ_2409 Let it Bead(Polya定理)
- POJ 2409 Let it Bead
- POJ 2409 Let it Bead(polya)
- POJ 2409 Let it Bead(Polya计数原理)
- poj 2409 Let it Bead (polya)
- poj 2409 Let it Bead(polya 定理)
- 【POJ 2409】Let it Bead(Polay 定理)
- [代码]POJ 2409 Let it Bead
- POJ - 2409 Let it Bead(波利亚计数)(欧拉函数)
- POJ 2409 Let it Bead (polya计数)