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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

NYOJ 269 VF

發布時間:2025/3/16 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NYOJ 269 VF 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

VF

時間限制:1000?ms ?|? 內存限制:65535?KB 難度:2 描述
Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as Pythagor’s theorem are already proved? Correct! He is to think out something his own, original. So he thought out the Theory of Vasya’s Functions. Vasya’s Functions (VF) are rather simple: the value of the?Nth?VF in the point?S?is an amount of integers from 1 to?N?that have the sum of digits?S. You seem to be great programmers, so Vasya gave you a task to find the milliard VF value (i.e. the VF with?N?= 109) because Vasya himself won’t cope with the task. Can you solve the problem? 輸入
There are multiple test cases.
Integer S (1 ≤ S ≤ 81).
輸出
The milliard VF value in the point S.
樣例輸入
1
樣例輸出
10
動態規劃!
如果找不到狀態轉移方程,直接遞歸求值,再打表!別怕麻煩哦!
遞歸代碼:
#include<stdio.h> #include<string.h> #define M 1000000000 __int64 num[85]; void fun(__int64 a,__int64 sum,__int64 m) {if(sum>M)return;__int64 i;num[m]++;for(i=0;i<=9;i++){fun(i,sum*10+i,m+i);} } int main() {__int64 n,i;memset(num,0,sizeof(num));for(i=1;i<=9;i++){fun(i,i,i);}while(~scanf("%I64d",&n)){printf("%I64d\n",num[n]);}return 0; }
打表:
AC碼:
#include<stdio.h> int f[82]={1,10,45,165,495,1287,3003,6435,12870,24310,43749,75501,125565,202005,315315,478731,708444,1023660,1446445,2001285,2714319,3612231,4720815,6063255,7658190,9517662,11645073,14033305,16663185,19502505,22505751,25614639,28759500,31861500,34835625,37594305,40051495,42126975,43750575,44865975,45433800,45433800,44865975,43750575,42126975,40051495,37594305,34835625,31861500,28759500,25614639,22505751,19502505,16663185,14033305,11645073,9517662,7658190,6063255,4720815,3612231,2714319,2001285,1446445,1023660,708444,478731,315315,202005,125565,75501,43749,24310,12870,6435,3003,1287,495,165,45,9,1}; int main() {int n;while(~scanf("%d",&n)){printf("%d\n",f[n]);}return 0; }
動態規劃!
AC碼:
#include<stdio.h> int dp[10][82]; void DP() {int i,j,k;for(i=1;i<10;i++)dp[1][i]=1;for(i=1;i<10;i++){// i表示有i位數字時for(j=1;j<=9*i;j++){// j表示變化范圍,當有i位數時,j的范圍[1,9*i]for(k=0;k<10&&k<=j;k++){dp[i][j]+=dp[i-1][j-k];}}} } int main() {int n,i,ans;DP();while(~scanf("%d",&n)){if(n==1)printf("10\n");else{ans=0;for(i=1;i<10;i++)ans+=dp[i][n];printf("%d\n",ans);}}return 0; }

總結

以上是生活随笔為你收集整理的NYOJ 269 VF的全部內容,希望文章能夠幫你解決所遇到的問題。

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