日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

北邮OJ 2016 网预-Square Coins

發布時間:2024/9/30 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 北邮OJ 2016 网预-Square Coins 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間限制?1000 ms?內存限制?65536 KB

題目描述

? ? Artoria, also known as Saber-chan, was born into a time of chaos and war that began with the demise of the Roman empire. Somewhere in the far east, people in Utopia know nothing about war or conflicts. They live in peace for quite a long time and developed a strange currency system. In particular, they use square coins. Not only have they square shapes but also their values are square integers. Coins with values of all square numbers up to 289?(=172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Utopia.

? ? According to the Utopia currency system, there are four combinations of coins to pay ten credits:

? ? ten 1-credit coins,
? ? one 4-credit coin and six 1-credit coins,
? ? two 4-credit coins and two 1-credit coins, and
? ? one 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Utopia. The answer may be very big, please output the answer module?1000000009.

輸入格式

The input begins with a line containing a single integer?T(1T2000), indicating the number of test cases. Each of the next?T?lines each containing an integer meaning an amount to be paid. You may assume that all the amounts are positive and less than?2000.?

輸出格式

? ? For each of the given amount, output one line containing a single integer representing the number of combinations of coins module?1000000009. No other characters should appear in the output.

輸入樣例

2 10 30

輸出樣例

4 27 物品有17種,無限取的容量有上限的背包,要求的是填滿時候有多少種裝法。

不難推出狀態方程:

for(i=1;i<=17;i++) ????for(j=0;j<=n;j++) ????????dp[j+i*i]=(dp[j]+dp[j+i*i])%mod;

dp[j]表示湊出j元錢的時候,有多少種湊法。

dp[j+i*i]表示,現在已經有了j元錢,我用i*i面額的貨幣可以得到j+i*i元錢,那就是用湊出j元的方法數dp[j]加上已有的湊出j+i*i元錢的方法數dp[j+i*i]再模運算一下即可。


答案即為dp[n]

#include<bits/stdc++.h> #define N 200010 #define ll long long #define M(x,y) x>y?x:y #define mod1 1000000009 #define clr0(x) memset(x,0,sizeof(x)) using namespace std; int main(){int n,t,ts,i,j,k,dp[5010];scanf("%d",&t);for(ts=1;ts<=t;ts++){int res=1;clr0(dp);scanf("%d",&n);dp[0]=1;for(i=1;i<=17;i++){for(j=0;j<=n;j++){dp[j+i*i]=(dp[j]+dp[j+i*i])%mod1;}}printf("%d\n",dp[n]);}return 0; }




總結

以上是生活随笔為你收集整理的北邮OJ 2016 网预-Square Coins的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。