! HDU 4345 The ring length of permutation group how many kinds of-DP

Source: Internet
Author: User

Test instructions: Permutation group, the length of the question ring how many kinds

Analysis:

The length of the ring is the least common multiple of each interval length you choose. The total interval length is n, so the question is how many least common multiple of each number of sums equals N.

Status: Dp[i][j] The optimal solution of the first I prime number, the interval length not exceeding J

Transfer: dp[i][j]=dp[i-1][j]+dp[i-1][j-k],k=prim[i]^1,2 ...

This question and the DP of the previous question is difficult to cry me.

Code:

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < String>using namespace Std;int n;long long dp[300][2000];int prim[300],vis[2000],cnt;void Is_prim () {Cnt=1;memset ( Vis,0,sizeof (VIS)); for (int i=2;i<=1000;i++) {if (!vis[i]) {prim[cnt++]=i;for (int j=i;j<=1000;j+=i) {vis[j]=1;}}}} void DP () {memset (dp,0,sizeof (DP)), for (Int. i=0;i<=1000;i++) dp[0][i]=1;for (int i=1;i<cnt;i++) {for (int j=0;j <=1000;j++) {dp[i][j]=dp[i-1][j];for (int k=prim[i];k<=j;k*=prim[i])   dp[i][j]+=dp[i-1][j-k];}} int main () {Is_prim ();DP(); while (scanf ("%d", &n)!=eof) {printf ("%i64d\n", Dp[cnt-1][n]);}}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

! HDU 4345 The ring length of permutation group how many kinds of-DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.